我有以下在SAS中使用的代碼提取,並希望將其寫入SQL Server中以提取數據。如何在SQL Server中使用substr?
substr(zipname,1,4) in("2000","9000","3000","1000");run;
如何在SQL Server中編寫此代碼?
我想和得到這個錯誤:
An expression of non-boolean type specified in a context where a condition is expected
我有以下在SAS中使用的代碼提取,並希望將其寫入SQL Server中以提取數據。如何在SQL Server中使用substr?
substr(zipname,1,4) in("2000","9000","3000","1000");run;
如何在SQL Server中編寫此代碼?
我想和得到這個錯誤:
An expression of non-boolean type specified in a context where a condition is expected
在SQL Server中,有沒有substr
功能(這是substring)
順便說一下,你需要一個完整的查詢......
select blabla
from blibli
where substring(zipname, 1, 4) in ('2000', '9000', 3000', '1000')
假設zipname是一個varchar或類似的東西...
從現在起,我絕對會用'blabla'列命名我的臨時表'blibli'。 –
@RaduGheorghiu不是最佳做法嗎? –
謝謝。有效!爲什麼我沒有想到子字符串?謝謝。 – user3197575
您需要一張表來獲取記錄,並且zipname是表格中的一列。聲明會是這樣的:
select * from tablename where substring(zipname,1,4) in ('2000','9000','3000','1000')
既然你想要第一個x個字符,你也可以使用left()函數。
where left(zipname, 4) in (values go here)
請記住,您的值必須單引號。你的問題有雙引號。
是不是'左(zipname,4)'? – Joe
翻譯這意味着什麼? 「IN」條款應該怎麼做? –
修復雙引號後,可以使用'left(zipname,4)'而不是'substring()'。 –