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 |
|
Linok
Starting Member
34 Posts |
Posted - 2006-07-12 : 14:02:10
|
Hey everyone,I'm working on this stored procedure that returns all the rows for an events calendar based on the date. However, now I need to modify it to not return rows that are a day before a certain row occurs. I'm really new to T-SQL and know that it'll require the DATEDIFF, but I'm not sure how to set it up.Here's the current SP:ALTER PROCEDURE coglej.sp_GetEventsForDate@eventdate datetime,@eventowner varchar (50)AS IF DATEDIFF(ww,GetDate(),@eventdate ) > 2 BEGINPRINT 'Getting early bird event price.'SELECT dbo.events.event_date, dbo.locations.city, dbo.locations.state, dbo.locations.name, dbo.locations.address1, dbo.locations.address2, dbo.locations.zip, dbo.locations.description, dbo.skus.sku_id, dbo.skus.event_type, dbo.skus.price, dbo.skus.slots_availableFROM dbo.events INNER JOIN dbo.locations ON dbo.events.location_id = dbo.locations.location_id INNER JOIN dbo.skus ON dbo.events.sku_id = dbo.skus.sku_idWHERE (dbo.events.event_date = CONVERT(datetime, @eventdate)) AND (dbo.skus.owner = @eventowner) AND (dbo.skus.price_type = 'Early')ENDELSEBEGINPRINT 'Getting regular event price.'SELECT dbo.events.event_date, dbo.locations.city, dbo.locations.state, dbo.locations.name, dbo.locations.address1, dbo.locations.address2, dbo.locations.zip, dbo.locations.description, dbo.skus.sku_id, dbo.skus.event_type, dbo.skus.price, dbo.skus.slots_availableFROM dbo.events INNER JOIN dbo.locations ON dbo.events.location_id = dbo.locations.location_id INNER JOIN dbo.skus ON dbo.events.sku_id = dbo.skus.sku_idWHERE (dbo.events.event_date = CONVERT(datetime, @eventdate)) AND (dbo.skus.owner = '@eventowner') AND (dbo.skus.price_type = 'Regular')END Does anyone have any ideas?I've tried adding " AND (DATEDIFF(dd, @eventdate, GetDate()) < 1)" to the end of the WHERE statements by no luck. |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-07-12 : 14:55:33
|
| [code]ALTER PROCEDURE coglej.sp_GetEventsForDate( @eventdate datetime, @eventowner varchar (50))AS IF DATEDIFF(ww, GetDate(), @eventdate ) > 2 BEGINPRINT 'Getting early bird event price.'SELECT dbo.events.event_date, dbo.locations.city, dbo.locations.state, dbo.locations.name, dbo.locations.address1, dbo.locations.address2, dbo.locations.zip, dbo.locations.description, dbo.skus.sku_id, dbo.skus.event_type, dbo.skus.price, dbo.skus.slots_availableFROM dbo.events INNER JOIN dbo.locations ON dbo.events.location_id = dbo.locations.location_id INNER JOIN dbo.skus ON dbo.events.sku_id = dbo.skus.sku_idWHERE (dbo.events.event_date >= DATEADD(ww, 2, getdate())) AND (dbo.skus.owner = @eventowner) AND (dbo.skus.price_type = 'Early')ENDELSEBEGINPRINT 'Getting regular event price.'SELECT dbo.events.event_date, dbo.locations.city, dbo.locations.state, dbo.locations.name, dbo.locations.address1, dbo.locations.address2, dbo.locations.zip, dbo.locations.description, dbo.skus.sku_id, dbo.skus.event_type, dbo.skus.price, dbo.skus.slots_availableFROM dbo.events INNER JOIN dbo.locations ON dbo.events.location_id = dbo.locations.location_id INNER JOIN dbo.skus ON dbo.events.sku_id = dbo.skus.sku_idWHERE (dbo.events.event_date < DATEADD(ww, 2, getdate())) AND (dbo.skus.owner = '@eventowner') AND (dbo.skus.price_type = 'Regular')END[/code]Peter LarssonHelsingborg, Sweden |
 |
|
|
|
|
|
|
|