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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.