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 |
|
azamsharp
Posting Yak Master
201 Posts |
Posted - 2009-11-11 : 17:00:23
|
| I need to perform the insert statement but stuck when the @Project is "1". When @Project is "1" I need to select the NOT NULL values for the Project. Here are some conditions: //When @Project = 0; Project column IS NULL// // @Project = 1; Project column IS NOT NULL// /// @Project = NULL; Both NULL & NOT NULL ValuesHere is the query: INSERT INTO #BT (Total) (Select SUM(Price) FROM #CMU WHERE B = 1 AND Project = CASE WHEN @Project = '1' THEN Project // this is trouble WHEN @Project = '0' THEN NULL END)Mohammad Azam www.azamsharp.net |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-11-12 : 01:44:15
|
| WHERE B = 1AND ((@Project = '1' and Project is not null)or(@Project = '0' and Project is null)or(@Project is null))MadhivananFailing to plan is Planning to fail |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2009-11-12 : 04:20:33
|
quote: Originally posted by madhivanan WHERE B = 1AND ((@Project = '1' and Project is not null)or(@Project = '0' and Project is null)or(@Project is null))MadhivananFailing to plan is Planning to fail
Super madhi!Yesterday I have read that question many times but my brain was blocked.I was always on the wrong way because I tried again and again to solve this using a CASE-statement.Good work! No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-11-12 : 05:50:48
|
quote: Originally posted by webfred
quote: Originally posted by madhivanan WHERE B = 1AND ((@Project = '1' and Project is not null)or(@Project = '0' and Project is null)or(@Project is null))MadhivananFailing to plan is Planning to fail
Super madhi!Yesterday I have read that question many times but my brain was blocked.I was always on the wrong way because I tried again and again to solve this using a CASE-statement.Good work! No, you're never too old to Yak'n'Roll if you're too young to die.
Thanks MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|