我在表名中有一列作为LOCATION CODE作为Company_Location 我想知道,如果用户输入Location_Code,它不应该已经存在于表
中答案 0 :(得分:2)
也许是这样的:
IF NOT EXISTS(
SELECT NULL FROM Company_Location
WHERE Company_Location.[LOCATION CODE]=<Some value>)
BEGIN
INSERT INTO Company_Location([LOCATION CODE])VALUES(<Some value>)
END
答案 1 :(得分:0)
if exists (select Location_code from Company_Location where Location_code=<something>
begin
...Do something here!!
end
else
PRINT 'records already exist'
答案 2 :(得分:0)
也许
SELECT case when [LOCATION CODE] IS NOT NULL then 'Yes' else 'No' end
FROM Company_Location
WHERE companyID = <value>