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 |
|
duncant
Starting Member
18 Posts |
Posted - 2010-11-15 : 12:15:55
|
| select ID, eMail from tbl_userswhere (ID IN (@EmailOne,@EmailTwo,@EmailThree))Problem is that sometimes there is only going to be 1 email, maybe 2 and sometimes 3.At the moment 3 is okay, 1 or 2 breaks the sql code, how would I account for 1 or 2 emails? |
|
|
Sachin.Nand
2937 Posts |
Posted - 2010-11-16 : 01:27:09
|
Doesn't quite make sense of what you are trying to say.declare @t table(id int)insert @tselect 1 union allselect 4 union allselect 7select * from @tdeclare @id1 int=1declare @id2 intdeclare @id3 int=7select * from @twhere id in(@id1,@id2,@id3) PBUH |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-11-16 : 03:12:56
|
| <<1 or 2 breaks the sql code,>>What did you mean by it?MadhivananFailing to plan is Planning to fail |
 |
|
|
duncant
Starting Member
18 Posts |
Posted - 2010-11-16 : 03:19:29
|
Ok, it made sense in my head .By 1 or 2, I mean the email parameters, i.e @EmailOne or @EmailTwo or @EmailThree.If there is only 1 or 2 parameters being passed to the sql code, how could I account for this?I appologise if I'm not making myself clear. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-11-16 : 04:39:13
|
| Put NULL as default value to the variablesMadhivananFailing to plan is Planning to fail |
 |
|
|
duncant
Starting Member
18 Posts |
Posted - 2010-11-16 : 05:24:09
|
Thanks, didn't know it was going to be that easy! |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-11-16 : 09:12:29
|
quote: Originally posted by duncant Thanks, didn't know it was going to be that easy! 
No problem MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|