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 |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2001-10-22 : 22:46:38
|
| Steve Hill writes "I have a table with several columns, int, smallint, tinyint, date, etc. I want to use a stored procedure which returns rows having criteria such as :c1=5, c2=don't care (inc nulls), c3=77It's the "don't care" bit that's stumped me. I've trawled the help and several forums but I can't find a wildcard for numerical or date fields like the "LIKE %" stuff for strings.Best I've come up with is an algorithm that uses theBETWEEN @x AND @ysyntax where @x=@y for specific values and don't care sets @x=min allowed and @y=max allowed for the particular field type in question. This totally ingores NULLs though.For example -CREATE PROCEDURE giveitup(@match int) ASDECLARE @x=int,@y=intIF @match IS NULL BEGIN SET @x=-32768 SET @y=32767 ENDELSE BEGIN SET @x=@match SET @y=@match ENDSELECT * FROM table1WHERE c1 BETWEEN @x AND @yThis seems really clumsy and doesn't take account of nulls. I need to extend it to all other columns in the table with AND in the WHERE clause also, but this should be trivial once the above is made to work.I'm running Win2k and SQL Server 2k.Can you help ?Steve" |
|
|
|
|
|