我是 TSQL 新手,试着要 MySQL 迁移到 TSQL,但有错误:7 q+ `5 m* e& V
SQLSTATE[42000]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Incorrect syntax near '='.带绑定参数SQL 查询:! F+ [# i7 q9 I# t5 q7 }
SELECT TOP(1) content.content_id AS content_id content.content_type AS content_type content.content_name AS content_name content.content_version AS content_version content.effective_date AS effective_date FROM test_content contentWHERE content.vendor_id = :vendor_idAND content.content_type = :content_typeAND CASE WHEN :content_type2 'T THEN content.content_name = :content_name ELSE 1=1 ENDORDER BY content_version DESC 查询语句:- @5 X) n7 f5 X9 B6 G
SELECT TOP(1) content.content_id AS content_id content.content_type AS content_type content.content_name AS content_name content.content_version AS content_version content.effective_date AS effective_date FROM test_content contentWHERE content.vendor_id = 127AND content.content_type = 'E'AND CASE WHEN 'E' 'T THEN content.content_name = 'ABC ELSE 1=1 ENDORDER BY content_version DESCTHENcontent.content_name = ‘ABC’似乎有问题。 有办法吗?CASE 动态数据在表达式中分配?4 h' j+ O7 l4 E' h
任何帮助帮助appriciated。1 ^$ N9 k5 @0 O4 ]& t) o( I, y) V
6 s9 a: J# e$ j" {3 ~9 T 解决方案: 5 b) g" ?1 y0 \ b2 B S
这是你所期待的吗?: b, n7 I0 c3 K' R$ u W
SELECT TOP(1) content.content_id AS content_id , content.content_type AS content_type , content.content_name AS content_name , content.content_version AS content_version , content.effective_date AS effective_date FROM test_content content WHERE content.vendor_id = :vendor_id AND content.content_type = :content_type AND content.content_name = CASE WHEN :content_type2 'T THEN :content_name ELSE content.content_name END ORDER BY content_version DESC