我正在尝试在 Sybase 中编写存储过程 (SP)。
SP 采用 5 个 varchar 参数。
根据传递的参数,我想构造要从特定表中选择的列名。
以下作品:
DECLARE @TEST VARCHAR(50) SELECT @TEST = "country" --print @TEST
execute("SELECT DISTINCT id_country AS id_level, Country AS nm_level FROM tempdb..tbl_books INNER JOIN (tbl_ch2_bespoke_report INNER JOIN tbl_ch2_bespoke_rpt_mapping ON tbl_ch2_bespoke_report.id_report = tbl_ch2_bespoke_rpt_mapping.id_report) ON id_" + @TEST + "= tbl_ch2_bespoke_rpt_mapping.id_pnl_level WHERE tbl_ch2_bespoke_report.id_report = 14")
但给了我多个结果:
1 1 行受影响。
id_level nm_level
1 4376 XYZ
2 4340 ABC
但是,我只想获得第二个结果。
我是否需要使用动态 SQL来实现这一点?
非常感谢您的帮助。
--Chapax