我正在撰寫一個存盤程序來獲取特定值。
declare @num int
set @num = (SELECT Id
FROM [sometable]
WHERE Name like '%today%')
-- returns @num = 1
Select Value
FROM [anothertable]
where name like 'days1'
在查詢的最后一行中,我想在“天”之后添加“1”或任何其他數字,具體取決于變數@num。
我該怎么做,有點像我們如何在 Javascript 中使用模板文字,使用 ${} 語法但在 SQL 中?
uj5u.com熱心網友回復:
您可以將第一個查詢用作第二個查詢的子查詢:
select [Value]
from anothertable
where [name] = Concat('days', (select Id from sometable where [Name] like '%today%'));
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/528473.html
標籤:sqlsql服务器
