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 |
|
skillile
Posting Yak Master
208 Posts |
Posted - 2001-12-12 : 11:53:37
|
| I am just not getting how to handle a case statement and then make it dynamic sql.I have a date coming in then I strip the weekday value and I am trying to seta case statement from that.Any help please.ALTER PROCEDURE s_cal_populate_clsavail(@oid int,@ddate varchar(20)='12/12/2001')ASDECLARE @vdate smalldatetimeDECLARE @weekday intDECLARE @strsql varchar(20)SET @vdate=convert(smalldatetime, @ddate, 101)SET @weekday=datepart(dw,@vdate)SET @strsql=' AND case ' + @weekday + 'when 1 then a.sun=1 when ' + @weekday +' = 2 then a.mon=2'----....etcselect a.cloid, b.timevaluefrom tblclavaildef ainner join tblclavailtime b on a.cloid=b.cloidwhere a.oid=@oidexec(@strsql)not sure if I can execute the @strsql in the middle of the where clause??Thanks slow down to move faster... |
|
|
barmalej
Starting Member
40 Posts |
Posted - 2001-12-12 : 12:19:39
|
| Try this without modifying your stored procedure and without dynamic sql. DECLARE @weekday as intDECLARE @vdate as datetimeSET @vdate=convert(smalldatetime, @ddate, 101)SET @weekday=datepart(dw, @vdate)select a.cloid,b.timevaluefrom tblclavaildef ainner join tblclavailtime b on a.cloid=b.cloidwhere a.oid=@oidand @weekday=case @weekday when 1 then a.sun when 2 then a.mon ---....etc end |
 |
|
|
skillile
Posting Yak Master
208 Posts |
Posted - 2001-12-12 : 12:35:33
|
| worked thanks.I am always trying to make if difficultslow down to move faster... |
 |
|
|
|
|
|