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