954,148 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

stored procedure problem

Hi

i am passing three parameters to my stored procedure.

now in stored procedure i want to execute the query on the basis of given condition.

suppose i m passing para1, para2 and para3.

now i want update table1

if(para1='' or para1= null) then
'update table1 set para2='''+@para2+''' and para3='''+@para3+''''
else
'update table1 set para1='''+@para1+''' and para2='''+@para2+''' and para3='''+@para3+''' '

how can i do this???


please help...


Thanks in advance

u4umang2001
Light Poster
28 posts since Nov 2007
Reputation Points: 10
Solved Threads: 0
 

Hi u4umang2001,

Right now I don't have near to me sample code, but could you take a look at Dynamic SQL?

See the following URL: http://msdn2.microsoft.com/en-us/library/aa258848.aspx

Hope this helps,

FeJoMeFa

FeJoMaFe
Newbie Poster
1 post since Feb 2008
Reputation Points: 10
Solved Threads: 0
 

hi u4umang2001,
if(para1='' or para1= null) then
'update table1 set para2='''+@para2+''' and para3='''+@para3+''''
else
'update table1 set para1='''+@para1+''' and para2='''+@para2+''' and para3='''+@para3+''' '
Your query is little bit simple but you should try first using various article. These articles can be easily found using Google. If you want to learn things, you should try atleast once.
Following is solution for your query.

CREATE PROCEDURE sp_myStoredProcedure
   @para1   varchar(100),
   @para2   varchar(100),
   @para3   varchar(100)
AS
   if @para1 IS NULL
        update table1 set para2=@para2 and para3=@para3
   else
        update table1 set para1=@para1 And para2=@para2 And para3=@para3
Go


Hope this will help you. Don't rely on others, first try yourself if not possible then ask for solution.
Thanks & Regards
Dilip Kumar Vishwakarma
Programmer .Net Consulting

dilipv
Light Poster
30 posts since Feb 2008
Reputation Points: 10
Solved Threads: 4
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You