sql insert語句加入條件判斷怎么寫
---不知道你說的是哪種情況,我理解的有2種,1是對插入源進行過濾,2是對插入的某些值作判斷,是某個特定值時轉換成另一個值
--情況1:使用Insert Into Select語法實現
--通過拼接結果集作為Select數據源之后可以加Where條件
Insert Into YourTable (id,name,status,remark)
Select id,name,status,remark From (
Select 1 as id,'張三' as name,'在職' as status,'沒有備注' as remark Union Select 2,'李四','離職',''
) as s Where id>2 And id
請問 sql語句中怎么做判斷 比如 if(aa=="1"){ insert into AA values('vv'
SQL的IF語句可以
IF 條件表達式
BEGIN
SQL語句
END
ELSE
BEGIN
SQL語句
END
例如
if @aa='1'
begin
insert into AA values('vv','cc')
end
else if @aa='2'
begein
insert into BB values('vv','cc')
end
else
begin
insert into CC values('vv','cc')
end
sql insert語句怎么寫
選擇:select * from 表名 where 條件
插入:insert into 表名(字段名1,字段名2) values(值1,值2)
刪除:delete from 表名 where 條件
更新:update 表名 set 要更新的字段名=值 where 條件
查找:select * from 表名 where 字段名 like '%值% '----------模糊查詢,如查蘇州,他會查出美蘇州,蘇州好等類似字段 /////////////////////////////////////這些是基本的增,刪,查,改的SQL語句,
ORACLE sql 里面可以用if 語句嗎
insert 語句中值的順序如果和表結構一致可以省略列名列表。
這個SQL的意思沒看懂,我給分析一下看對不對,
你是不是想表達這個意思:
如果在yangao這個表中存在age3=4的數據,那么,就向yangao中插入一行數據,行數據的內容是(4,NULL,1).
如果是這樣的話,那么IF用的是不對的。
在SQL里面條件的關鍵字是WHERE。
insert into yangao values(4,NULL,1)
where exists (select * from yangao where(AGE3=4));
commit;
但如果你想表達的是:
在yangao表中插入一條數據,如果存在(select * from yangao where(AGE3=4)) 這樣的數據就提交的話,那么應該這么寫:
insert into yangao values (4, NULL, 1);
select count(*) into n_count from yangao where (AGE3 = 4);
if n_count > 0 then
commit;
end if;
SQL IF 語句
來晚了~
關于判斷語句看數據庫吧
SQL server 支持的查詢語句命令case when:
結構如下:
case
when 條件1 then 結果1
when 條件2 then 結果2
……
end
在access中,不支持case when 結構,使用 iif 代替:
結構如下:
IIF(條件,結果1,結果2)
解釋:當條件成立,取結果1;當條件不成立,取結果2
IIF(TypeID=-1,'一般客人',(select * from ClubType where * =*)) as TypeName
ORACLE sql 里面可以用if 語句嗎
insert 語句中值的順序如果和表結構一致可以省略列名列表。
這個SQL的意思沒看懂,我給分析一下看對不對,你是不是想表達這個意思:如果在yangao這個表中存在age3=4的數據,那么,就向yangao中插入一行數據,行數據的內容是(4,NULL,1).如果是這樣的話,那么IF用的是不對的。在SQL里面條件的關鍵字是WHERE。
insert into yangao values(4,NULL,1) where exists (select * from yangao where(AGE3=4)); commit;但如果你想表達的是:在yangao表中插入一條數據,如果存在(select * from yangao where(AGE3=4)) 這樣的數據就提交的話,那么應該這么寫: insert into yangao values (4, NULL, 1); select count(*) into n_count from yangao where (AGE3 = 4); if n_count > 0 then commit; end if;。
轉載請注明出處華閱文章網 » sqlif語句insert