我是 sql 服务器的新手。我用google搜索了coalesce的用法,发现它是ISNULL的替代词。
我在论坛上看到了一段关于合并的不同用途的代码。
use adventureworks
DECLARE @DepartmentName VARCHAR(1000)
SELECT @DepartmentName = COALESCE(@DepartmentName,'') + Name + ';'
FROM HumanResources.Department
WHERE (GroupName = 'Executive General and Administration')
SELECT @DepartmentName AS DepartmentNames
它在一行中返回结果。
那么,为什么 sql 在 .NET 中默认不支持字符串连接,如下所示?
DECLARE @DepartmentName VARCHAR(1000)
**SELECT @DepartmentName = @DepartmentName + Name + ';'**
FROM HumanResources.Department
WHERE (GroupName = 'Executive General and Administration')
SELECT @DepartmentName AS DepartmentNames
下面的行中合并的用途是什么
SELECT @DepartmentName = COALESCE(@DepartmentName,'') + Name + ';'
为什么
**SELECT @DepartmentName = @DepartmentName + Name + ';'**
FROM HumanResources.Department
WHERE (GroupName = 'Executive General and Administration')
不管用?