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 |
|
JeniQ
Starting Member
29 Posts |
Posted - 2009-09-21 : 16:19:29
|
| Greetings, I'd like to set a variable equal to more than one constant. For example, I have a field called RecordStatus. The options for RecordStatus include A, P, I, R, and D. It is possible to logically group these status into the following categories:Current = A, PHistorical = I, R, DAll = A, P, I, R, DIn a stored proc that I'm writing, I want to easily reference either Current, Historical or All. So I was trying something like this:declare @all nvarchar(35)set @all = ('A' , 'P', 'R', 'I', 'D')select ResearchID, RecordStatus from Research where RecordStatus = @all But that doesn't work. Any suggestions as how I can achieve my goal? |
|
|
AjarnMark
SQL Slashing Gunting Master
3246 Posts |
Posted - 2009-09-21 : 19:24:55
|
| What you're describing is an IN statement or dealing with comma-separated values (CSVs). One way to do this is to create table variables and insert the values you want to equate to each variable, and then you could do something like SELECT ResearchID, RecordStatusFROM ResearchWHERE RecordStatus IN (Select value from @CurrentTableVar)You also might want to use the search box on this site and search for the term CSV to find other articles on this topic.--------------------------------------------Brand yourself at EmeraldCityDomains.com |
 |
|
|
|
|
|
|
|