Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
M.E.
Aged Yak Warrior
539 Posts |
Posted - 2002-11-27 : 19:47:38
|
| I don't want to use dynamic sql for this...I have 3 variables coming into a stored procedure. @REI@DB@ASUI then do an insert into a table with data from a different one. Heres the first part....insert into tableA(value)select valueA from MyTablewhere mytable.REI = @REIand heres where the interesting part comes in the next part of the code looks kinda like this... (psuedo code here)if @db is not null Mytable.DB = @DBelsemytable.ASU = @ASU(pretty much if @DB has a value, the where statement points to mytable.DB If @DB is null then use mytable.ASU)The only method I have come up with isIf @DB is not null then Insert into --blah blah blah.. Use mytable.db = @DBelse insert into --blah blah blah.. Use Mytable.ASU = @ASUIs there any other way to handle this other then dynamic SQL or an if statement? I know I could make the insert statement into 2 stored procs...if @db is not null exec storedprocDB @REI = @REI, @DB=@DBelse exec storedprocASU @REI = @REI, @ASU=@ASU-----------------------SQL isn't just a hobby, It's an addiction |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2002-11-27 : 20:04:36
|
| How about:insert into tableA(value) select valueA from MyTable where mytable.REI = @REI AND IsNull(@DB, @ASU)=CASE WHEN @DB IS NULL THEN mytable.ASU ELSE mytable.DB END |
 |
|
|
M.E.
Aged Yak Warrior
539 Posts |
Posted - 2002-11-28 : 13:14:48
|
| Beauty Rob.... Need to remember the uses of isnull. ThanksMark-----------------------SQL isn't just a hobby, It's an addiction |
 |
|
|
|
|
|