Re: Using variables in Dynamic SQL
From: Robert Zirpolo (robert.zirpolo_at_phoenixdb.co.uk)
Date: 08/31/04
- Next message: Martin Juricek: "Re: I have problem with following error message"
- Previous message: Hugo Kornelis: "Re: Using variables in Dynamic SQL"
- In reply to: Robert Zirpolo: "Re: Using variables in Dynamic SQL"
- Next in thread: Robert Zirpolo: "Re: Using variables in Dynamic SQL"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 31 Aug 2004 08:02:54 -0700
The workaround I have used is that I have setup a second variable which
performs the dateadd function so I can simply reference this in the
where clause. The finished script...
DECLARE @sql varchar(5000)
DECLARE @StartDate datetime
DECLARE @EndDate datetime
DECLARE @EndDate2 datetime
DECLARE @Media nvarchar(500)
DECLARE @Analysis nvarchar(500)
SELECT @StartDate = '01/07/00'
SELECT @EndDate = '31/12/04'
SELECT @EndDate2 = dateadd(day,1,@Enddate)
SELECT @Media = '1, 2, 3'
SELECT @Analysis = '%'
set @sql =
''Departing from ''+ '''+convert(char(10),@startdate,103)+''' +'' to
''+ '''+convert(char(10),@enddate,103)+''' as ''ReportString''
from booking as b
where (b.disabled = 0)
and (b.leadsector = 1)
and (b.mediaid in ('+ @media +')
and (b.analysiscodeid like '''+ @analysis +''')
and (se.departureDateTime >= '''+convert(char(10),@startdate,103)+''')
and (se.departureDateTime < '''+convert(char(10),@enddate2,103)+''')'
exec(@sql)
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
- Next message: Martin Juricek: "Re: I have problem with following error message"
- Previous message: Hugo Kornelis: "Re: Using variables in Dynamic SQL"
- In reply to: Robert Zirpolo: "Re: Using variables in Dynamic SQL"
- Next in thread: Robert Zirpolo: "Re: Using variables in Dynamic SQL"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|