Hi list,
I'm trying to write a sproc and part of it will need to return the min value of a column to a variable. So it's something like
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
create procedure sproc_name (@tbl_name varchar(100), @colName varchar(100))
as
declare
@MinValue datetime, -- all input columns are datetime column
@sqlstmt varchar(2000)
set @sqlstmt = 'select @minValue = min( '+@colName + ') from dbo.' + @TblName
exec (@sqlstmt)
.....
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
However, when I tried to run it, it kept complaining
' need to declare @minValue '
Which I think is coming from the 'set @sqlstmt' statement.
So how do I assign the minimum value of an input column to a variable?
Thanks a lot,
Elaine
MS Sql Server LazyDBA home page