none
Incorrect syntax near '12'.

    Question

  • A variable in a stored procedure.

    What's wrong?


    if @PeriodType = 'Today' or @PeriodType = 'Yesterday'
            select @MfilterBy2 =' and BUS_DT = ''' + substring(@BeginDate,1,10) + ' 12:00'''

    Thanks
    Tuesday, December 16, 2008 10:00 PM

Answers

  • DECLARE @PeriodType NVARCHAR(150); 
    DECLARE @BeginDate NVARCHAR(MAX); 
    DECLARE @MfilterBy2 NVARCHAR(MAX); 
    SET @PeriodType = 'Today'
    SET @BeginDate = '2008-10-10 12:25'
    if @PeriodType = 'Today' or @PeriodType = 'Yesterday' 
            SET @MfilterBy2 =' and BUS_DT = ''' + substring(@BeginDate,1,10) + ' 12:00''' 
     
    print @MfilterBy2; 

    Doesn't produce any error in SQL2005 here!!! and the output of the previous script here is:

     and BUS_DT = '2008-10-10 12:00'

    Groupe-CDGI Developper
    • Marked as answer by ardmore Tuesday, December 16, 2008 10:11 PM
    Tuesday, December 16, 2008 10:07 PM