Hi,
Can we use a parameter that is a column name in a function ?
Here's my function :
CREATE FUNCTION dbo.fn_counting (@colnumber varchar(2),@num ber
varchar(1))
RETURNS int AS
BEGIN
DECLARE @column varchar(2)
DECLARE @ColTotal int
SET @column = 'R' +@colnumber
(This next line WORKS !!!)
SELECT @ColTotal = COUNT(*) FROM dbo.Tbl_Answers WHERE R3 = @number
(This next one DOESN'T WORK - because of the ' it is treated as a
string)
SELECT @ColTotal = 'COUNT(*) FROM dbo.Tbl_Answers WHERE ' +@column +
'=' +@number
RETURN @ColTotal
END
Thank you
Can we use a parameter that is a column name in a function ?
Here's my function :
CREATE FUNCTION dbo.fn_counting (@colnumber varchar(2),@num ber
varchar(1))
RETURNS int AS
BEGIN
DECLARE @column varchar(2)
DECLARE @ColTotal int
SET @column = 'R' +@colnumber
(This next line WORKS !!!)
SELECT @ColTotal = COUNT(*) FROM dbo.Tbl_Answers WHERE R3 = @number
(This next one DOESN'T WORK - because of the ' it is treated as a
string)
SELECT @ColTotal = 'COUNT(*) FROM dbo.Tbl_Answers WHERE ' +@column +
'=' +@number
RETURN @ColTotal
END
Thank you
Comment