September 7, 2005 at 9:51 pm
, I have another case where I need to use EXECUTE TO UPDATE certain table, and also to INSERT...
DECLARE @tbl nvarchar(125), @lookupvalue nvarchar(125), @lookuporder nvarchar(125), @lvid nvarchar(125)
I want to use those variable for UPDATE... using EXEC sp_executesql...
SET @sql=('UPDATE @tbl SET fieldname=@fieldname, lookupvalue=@lookupvalue, lookuporder=@lookuporder WHERE lvid=@lvid')
EXEC sp_executesql @sql, N'@lvid nvarchar(125), @lookupvalue nvarchar(125), @lookuporder numeric(9), @fieldname nvarchar(125), @tbl nvarchar(125)'....im not sure what code to fill in here.
I will also use the same variables(except @lvid) for INSERT to @tbl.
I just want my StoredProcedure to be flexible.
Need Help...
September 7, 2005 at 10:08 pm
You also need to learn sql programming. This is basically the worst possible way to use sql server's stored proc. You need to create one statement for each possible operation if you want to harnest the server's power.
September 8, 2005 at 1:56 am
I agree. You either have the cat by the tailpiece, or you are giving us insufficient info, hehehe .
Anyway, you can use at least some of this:
Replace the BOLD RED with your values...
DECLARE @sql nvarchar(4000),
@fieldname nvarchar(50),
@tbl nvarchar(125),
@lookupvalue nvarchar(125),
@lookuporder nvarchar(125),
@lvid nvarchar(125)
SET @fieldname = 'FIELDNAME'
set @tbl = 'TBL'
set @lookupvalue = 'LOOKUPVALUE'
set @lookuporder = 'LOOKUPORDER'
set @lvid = 'LVID'
SET @sql = 'UPDATE ' + @tbl + ' SET fieldname=' + @fieldname + ', lookupvalue='
set @sql = @sql + @lookupvalue + ', lookuporder=' + @lookuporder + ' WHERE lvid=' + @lvid
print @sql --use this to check first
EXEC @sql
<hr noshade size='1' width='250' color='#BBC8E5'>Kindest Regards,
Roelof
<a href='http://' class='authorlink' target='_blank'></a>
--There are only 10 types of people in the world. Those who understand binary, and those who don't.
September 8, 2005 at 2:57 am
Yup! it worked! thanks buddy. Actually, its not a sufficient info, my info are just enough thats why you(Roelof) created the solution. For me, if it is insufficient, you will be askin for more info. Anyway Guys, THANK YOU VERY MUCH.
September 8, 2005 at 3:03 am
Happy to help.
i had a lucky guess, i guess...
<hr noshade size='1' width='250' color='#BBC8E5'>Kindest Regards,
Roelof
<a href='http://' class='authorlink' target='_blank'></a>
--There are only 10 types of people in the world. Those who understand binary, and those who don't.
September 8, 2005 at 6:30 am
Dude it's just not the way to program in sql, you relly need to get aquinaed with these article.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply