动态T-SQL IIF语句出现问题 [英] Trouble with Dynamic T-SQL IIF Statement

查看:118
本文介绍了动态T-SQL IIF语句出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此代码可以正常工作,并且完全满足我的要求,即对动态查询的每个实例的数量*价格求和。

This code works fine and does exactly what I want, which is to sum the Qty * Price for each instance of the dynamic query.

但是当我添加IIF语句时,它会中断。我想做的事情与上述相同,但是当事务类型为 CO时,将总和设置为负数。

But when I add an IIF statement it breaks. What I am trying to do is the same thing as above but when the transaction type is 'CO' set the sum to a negative amount.

推荐答案

问题原来是 NVARCHAR(4000)类型的 @sql ,将其长度限制为4000个字符:查询在其中添加了另一个长块后,在某个随机位置被截断。

The problem turned out to be the NVARCHAR(4000) type of @sql, limiting its length to 4000 characters: the query got truncated at some random place after adding another long chunk to it.

DECLARE @sql NVARCHAR(MAX)解决问题,允许动态查询小于2GB的任何大小。

DECLARE @sql NVARCHAR(MAX) solves the problem, allowing a dynamic query of any size below 2GB.

这篇关于动态T-SQL IIF语句出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆