read data from fields between 2 dates?

  • Hi, I'm trying to duplicate the following code from a SP but using Dynamic SQL

    select [JOHN BROWN] from [resource] where  [date] BETWEEN @sDate1 AND @sDate2

    What I've got so far is :

    SET @CMD = 'SELECT @Rtn = [' + @ColName + '] from [Resource]' + ' where [date] between ''' + @sDate1 + ''' + and + ''' @sDate2 + ''''

    exec sp_executesql @CMD,N'@Rtn varchar (200) out',@Status out

    but I can't seem to get the correct syntax, can anyone help please. I also need it to return a record set

  • try this one

    SET @CMD = 'SELECT [' + @ColName + '] from [Resource]' + ' where [date] between ''' + @sDate1 + ''' + and + ''' @sDate2 + ''''

    exec sp_executesql @CMD


    Rohit

  • many thanks Rohit, that works great

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply