Insert into mutiple sql tables
Last Post 12-16-2009 06:53 AM by Michael Man. 2 Replies.
AddThis - Bookmarking and Sharing Button
Author Messages
Michael ManUser is Offline
river guide
river guide
Posts:152
Avatar

--
12-15-2009 12:26 PM

    I have a form that has 4 single text input fields

    InputA, InputB, InputC, InputD

    When user click on submit, I want to use dynamic SQL statement to insert these 4 input into 4 different tables. So inputA will go to tableA, InputB goes to TableB, InputC goes to TableC ,etc.

    However, I want to check if any input field is empty (null) then skip that table and move on the next input

    Can someone give me an idea how to do this?

    Thanks

    David ToUser is Offline
    river guide
    river guide
    Posts:2719
    Avatar

    --
    12-16-2009 06:31 AM
    Calling a stored procedure to pass in all the parameters would be a better way to go. In your completion event:

    usp_insert '$(InputA)','$(InputB)','$(InputC)','$(InputD)'

    where the input parameters represent your shortname on your DF page.
    Your stored procedure, which you execute under Host / SQL or SQL Management Studio, would be something like:

    create procedure usp_insert (@InputA nvarchar(200),@InputB nvarchar(200),@InputC nvarchar(200),@InputD nvarchar(200))
    as
    begin
    if @InputA != '' insert into TableA(columnname) values(@InputA)
    if @InputB != '' insert into TableB(columnname) values(@InputB)
    if @InputC != '' insert into TableC(columnname) values(@InputC)
    if @InputD != '' insert into tableD(columnname) values(@InputD)
    end

    -- David
    Michael ManUser is Offline
    river guide
    river guide
    Posts:152
    Avatar

    --
    12-16-2009 06:53 AM
    Posted By David To on 12/16/2009 8:31 AM
    Calling a stored procedure to pass in all the parameters would be a better way to go. In your completion event:

    usp_insert '$(InputA)','$(InputB)','$(InputC)','$(InputD)'

    where the input parameters represent your shortname on your DF page.
    Your stored procedure, which you execute under Host / SQL or SQL Management Studio, would be something like:

    create procedure usp_insert (@InputA nvarchar(200),@InputB nvarchar(200),@InputC nvarchar(200),@InputD nvarchar(200))
    as
    begin
    if @InputA != '' insert into TableA(columnname) values(@InputA)
    if @InputB != '' insert into TableB(columnname) values(@InputB)
    if @InputC != '' insert into TableC(columnname) values(@InputC)
    if @InputD != '' insert into tableD(columnname) values(@InputD)
    end

    -- David


    Thanks for your help. I will try it and let you know
     

    Thanks again



    ---
  • 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