很遗憾,我执行了此查询,并且我的网站现在无法正确显示SQL数据库中的某些值。谁能解释这个查询的实际作用?
DECLARE @SQL NVARCHAR(MAX)
SET @SQL = CAST(REPLICATE(N'A',3000) AS NVARCHAR(MAX)) + CAST(REPLICATE(N'B',3000) AS NVARCHAR(MAX))
SELECT LEN(@SQL)
答案 0 :(得分:4)
让我们破坏您的代码:
-- string variable declaration @SQL at this moment it is NULL
DECLARE @SQL NVARCHAR(MAX)
-- assign to variable @SQL concatentation of AAA...AAABBB...BBB
-- 3000 3000
SET @SQL = CAST(REPLICATE(N'A',3000) AS NVARCHAR(MAX)) + CAST(REPLICATE(N'B',3000) AS NVARCHAR(MAX))
--get length of string (6000 = 3000 + 3000)
SELECT LEN(@SQL)