I'm new to sql server. I googled the use of coalesce and find out it is another words a replace of ISNULL.I came across a piece of code posted in the forum about the different uses of coalesce.use adventureworksDECLARE @DepartmentName VARCHAR(1000)SELECT @DepartmentName = COALESCE(@DepartmentName,'') + Name + ';' FROM HumanResources.DepartmentWHERE (GroupName = 'Executive General and Administration')SELECT @DepartmentName AS DepartmentNameswhich return the result in a single line.So why sql does not support string concatenation by default as in .NET like below?DECLARE @DepartmentName VARCHAR(1000) **SELECT @DepartmentName = @DepartmentName + Name + ';'** FROM HumanResources.Department WHERE (GroupName = 'Executive General and Administration') SELECT @DepartmentName AS DepartmentNames
what is the use of coalesce in the below lineSELECT @DepartmentName = COALESCE(@DepartmentName,'') + Name + ';'
and why**SELECT @DepartmentName = @DepartmentName + Name + ';'** FROM HumanResources.Department WHERE (GroupName = 'Executive General and Administration')
is not working?