Great Ideas. Always Flowing.

We are not happy until you are happy. Client satisfaction guaranteed. Whatever your needs and requirements, we have the skills and resources for the job!

Quick login...


Or... now make it easy with Facebook Integration
Connect via Facebook



Top Sellers

Frustrated over the lack of customization for your user's registration fields? Dynamically setup your DNN Portal with custom registration fields, layout, questions, and other core integration options......

Ultra Video Gallery is a brother product of Ultra Media Gallery, UVG allows you to upload videos in various format and automatically encode them to flv or H264 format, you also can add videos from internet or record live videos from your webcam.

Build high performance, completely customizable data-entry forms and views driven by your DNN and external databases. New built-in tools make it a snap to quickly create data entry forms, data views, and even database tables. Plus, add your own HTML, CSS, Javascript, SQL commands, stored procedures,

The most advanced DotNetNuke shopping cart on the planet. Easy to use e-Commerce, Secure Shopping Cart Software and SEO friendly. B2C / B2B Ecommerce Sites.

One stop solution for events calendar and events registration! FREE DOWNLOAD is available now!

SQL question - using CASE and INSERT
Last Post 01-20-2011 08:37 AM by Ryan Bakerink. 3 Replies.
AddThis - Bookmarking and Sharing Button Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
jtigerUser is Offline
skipping stones
skipping stones
Posts:11
Avatar

--
01-07-2011 02:35 PM
    Hi there,

    I'm using Dynamic Forms to capture some data and I'm trying to set up a conditional data capture.  I have the user entering a zip code and if the zip is in my table, then the data gets populated in table_X, but if it's not in the zip table, then it gets populated in table_Y.

    I'm no longer getting errors, but the data does not seem to be going into the table.  Any help with this is appreciated.  Here is my current code:

    SELECT zip =
        CASE
            WHEN zip = 12345
            THEN
                'INSERT INTO table_X (name,email,zip)
                VALUES ($(name),$(email),$(zipcode))'
            ELSE
                'INSERT INTO table_Y (name,email,zip)
                VALUES ($(name),$(email),$(zipcode))'
        END
    FROM zipcodes;

    I've had previous attempts at this and the respective errors are below each:

    Try #1:
    SELECT zip FROM zipcodes
    CASE WHEN zip = '12345'
    THEN INSERT INTO table_X (name,email,zip)
    VALUES ('$(name)','$(email)','$(zipcode)')
    ELSE INSERT INTO TESTtable_Y (name,email,zip)
    VALUES ('$(name)','$(email)','$(zipcode)')
    END ;

    Incorrect syntax near the keyword 'CASE'. Incorrect syntax near the keyword 'ELSE'..


    Try #2:
    SELECT zip = CASE
    WHEN zip = 12345
    THEN INSERT INTO table_X (name,email,zip)
    VALUES ('$(name)','$(email)','$(zipcode)')
    ELSE INSERT INTO table_Y (name,email,zip)
    VALUES ('$(name)','$(email)','$(zipcode)')
    END
    FROM zipcodes;

    Incorrect syntax near the keyword 'INSERT'. Incorrect syntax near the keyword 'ELSE'. Incorrect syntax near the keyword 'FROM'.


    Try #3:
    SELECT zip = CASE
    WHEN zip = 12345
    THEN 'INSERT INTO table_X (name,email,zip)
    VALUES ('$(name)','$(email)','$(zipcode)')'
    ELSE 'INSERT INTO table_Y (name,email,zip)
    VALUES ('$(name)','$(email)','$(zipcode)')'
    END
    FROM zipcodes;

    Incorrect syntax near '$(name)'.

    Thanks much!

    -Jahn

    Ryan BakerinkUser is Offline
    river guide
    river guide
    Posts:1900
    Avatar

    --
    01-19-2011 01:22 PM
    Hello Jahn,

    Please review this link double check on using the CASE statement:


    http://www.jackdonnell.com/articles...L_CASE.htm


    http://stackoverflow.com/questions/...n-question


    http://articles.techrepublic.com.co...78041.html

    Please let me know if these resources help.

    Thanks,

    Ryan
    jtigerUser is Offline
    skipping stones
    skipping stones
    Posts:11
    Avatar

    --
    01-19-2011 09:11 PM
    Hi Ryan,

    I was just recently (the day before your post) able to find a solution to this problem and it didn't use CASE at all. Go figure. Below is the code that worked for me.

    if not exists(SELECT zip FROM zipcodes WHERE zip='$(zipcode)')
    begin
    INSERT INTO tableY (thename,theemail,thezip) VALUES ('$(name)','$(email)','$(zipcode)')
    end
    else
    begin
    INSERT INTO tableX (thename,theemail,thezip) VALUES ('$(name)','$(email)','$(zipcode)')
    end

    Thanks again for your assistance.

    -Jahn
    Ryan BakerinkUser is Offline
    river guide
    river guide
    Posts:1900
    Avatar

    --
    01-20-2011 08:37 AM
    Hello Jahn,

    I'm glad that you've found a solution to this.

    If you ever have any questions please let me know.

    Thanks,

    Ryan
    You are not authorized to post a reply.


     
     

    Join our mailing list...

    Get current news and events the easy way
    Subscribe Me

    Recent Blogs...

     
    Copyright 2005 - 2011 by Data Springs, Inc.
     
  • film izle
  • 720 izle
  • film
  • sinema izle
  • film makinesi
  • T�rk�e dublaj film
  • film izle
  • film izle
  • baglan film izle
  • sinema izle
  • 1080 film izle
  • film mercegi