SQLTeam.com | Weblogs | Forums

Assign concatenate to variable

#1

Hi All.

I try to assign concatenation to variable:

Declare @SelectString as varchar(100)

If @SelectText = 0
Set @SelectString = 'Select'
Else
SELECT
@SelectString = (FName + LName) EmployeeName
FROM dbo.Employeess

But I got red wave line under FName, LName - invalid column name and under EmployeeName incorrect syntax. How to fix problem?

Thanks

#2

You can't assign a variable value and assign a column name -- it's one or the other.

SELECT
@SelectString = (FName + LName)
FROM dbo.Employeess