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 |
|
Pinto
Aged Yak Warrior
590 Posts |
Posted - 2005-12-13 : 04:58:24
|
| I'm starting all over again with my previous problem. This is my sp which doesn't work as I'm using IN which I believe you can only use with a dynamic sp. Can anyone help me convert this sp to a dynamic one please.CREATE Procedure [spRB_GetAvailableRooms2]@strDateRequired datetime,@strListOption nvarchar(12),@strRoomList nvarchar (2000),@strRoomref nvarchar (10)asif @strListOption ='No'BEGINSelect *from vweAvailableRooms whereBD_RoomRef =@strRoomRef andBD_DateRequired =@strDateRequired ORDER BY BD_RoomRef, BD_DateRequired ascENDif @strListOption ='ThisMonth'BEGINSelect *from vweAvailableRooms where BD_RoomRef IN (''' + Replace(@strRoomList,',',''',''') + ''') andMonth(BD_DateRequired)= Month(@strDateRequired)ORDER BY BD_RoomRef, BD_DateRequired ascENDGO |
|
|
surendrakalekar
Posting Yak Master
120 Posts |
Posted - 2005-12-13 : 05:55:24
|
quote: Originally posted by Pinto[brThis is my sp which doesn't work as I'm using IN ...
What is the problem?Whether it iw throwing any error or not showing any records?Surendra |
 |
|
|
Pinto
Aged Yak Warrior
590 Posts |
Posted - 2005-12-13 : 06:13:21
|
| It isn't showing any records. |
 |
|
|
shallu1_gupta
Constraint Violating Yak Guru
394 Posts |
Posted - 2005-12-13 : 06:17:43
|
| Hi,U can insert ur comma separated string into a table variable and use that in ur IN clause |
 |
|
|
Kristen
Test
22859 Posts |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
Pinto
Aged Yak Warrior
590 Posts |
Posted - 2005-12-13 : 09:10:40
|
| I solved it like this, but not in an sp. 'This builds a string of the rooms that this user is allowed to view from the Room listbox If Me.LBRooms.SelectedIndex = 0 Then For n = 1 To Me.LBRooms.Items.Count - 1 strRoomList = strRoomList & "'" & Me.LBRooms.Items(n).Text & "'," Next n strRoomList = strRoomList.Substring(0, strRoomList.Length() - 1) Me.Session("RoomRefLogin") = strRoomList Else Me.Session("RoomRefLogin") = Me.LBRooms.SelectedValue End If'This gets the records Select Case Me.Session("ListOption") Case "No" mySQLstr = "SELECT * from vweAvailableRooms where BD_RoomRef IN (" & Me.Session("RoomRefLogin") & ")" _ & "and BD_DateRequired = '" & Me.Session("DateRequiredLogin") & "' ORDER BY BD_RoomRef Asc" Case "ThisMonth" mySQLstr = "SELECT * from vweAvailableRooms where BD_RoomRef IN (" & Me.Session("RoomRefLogin") & ")" _ & "and Month(BD_DateRequired) = '" & Month(Me.Session("DateRequiredLogin")) & "' ORDER BY BD_RoomRef, BD_DateRequired Asc" End SelectThanks everyone for your help |
 |
|
|
|
|
|
|
|