Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ember.js/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用CONVERT处理动态SQL中的合并_Sql_Tsql_Stored Procedures_Dynamic Sql - Fatal编程技术网

使用CONVERT处理动态SQL中的合并

使用CONVERT处理动态SQL中的合并,sql,tsql,stored-procedures,dynamic-sql,Sql,Tsql,Stored Procedures,Dynamic Sql,这是一个存储过程,它连接表以检索所需的结果。它需要通过@cha_id对其进行过滤,如果用户没有提供,它将相应地接受tablea中的任何内容。如何处理动态SQL查询中的合并?我无法获取它,因为@cha_id也应该进行转换。例如,如果不需要COALESCE或ISNULL,这将起作用 WHERE tablea.chan_id = '''+CONVERT(VARCHAR,@chan_id)+''' 会有用的。但是我无法在需要COALESCE/ISNULL的情况下找到它 WHERE tablea.ch

这是一个存储过程,它连接表以检索所需的结果。它需要通过@cha_id对其进行过滤,如果用户没有提供,它将相应地接受tablea中的任何内容。如何处理动态SQL查询中的合并?我无法获取它,因为@cha_id也应该进行转换。例如,如果不需要COALESCE或ISNULL,这将起作用

WHERE tablea.chan_id = '''+CONVERT(VARCHAR,@chan_id)+''' 
会有用的。但是我无法在需要COALESCE/ISNULL的情况下找到它

WHERE tablea.chan_id = COALESCE(CONVERT(VARCHAR,@chan_id),tablea.chan_id)
我一直在徒劳地研究。任何帮助都将不胜感激

试试下面的方法

  'SELECT * FROM tablea WHERE tablea.changelogtype_id= COALESCE(' + @cha_id + ', tablea.chan_id)'

非常感谢。这将在正常脚本下工作。但我需要在动态SQL中使用它。