-1

this :にA列 sayidと属性を持つテーブルがあります。特定の列を検索して11などのアクションを実行するような方法でSQLクエリが必要です。それ以外の場合は、その(11)値を持つ新しい行を挿入します。id1 to 20 or any othersQueryid

要するに

Search 11 in id if found then update 11 to 12 otherwise insert 11 into id
4

4 に答える 4

2
if not exists(select id from some table Where id = @someid)
begin
  insert sometable(id) Values (@id)
end
else
begin
 /* do something else */
end

複雑にしないでおく...

于 2013-06-25T09:55:47.283 に答える
2

を使用しIf...Elseます。

IF EXISTS (SELECT * FROM TABLE_NAME WHERE id=11)
 BEGIN
     UPDATE TABLE_NAME SET ..set column with values
 END
ELSE
 BEGIN
      INSERT INTO TABLE_NAME VALUES (values....);
 END
于 2013-06-25T10:07:45.983 に答える
0

あなたのリクエストにクエリがあるかどうかはわかりませんが、 php 、 asp などを使用して条件付き注文で個別に実行できると思います.PHPの例は次のとおりです:

<?php
$number = 11 ;
$query = mysql_query("select * from `table` where `id` = '".$number."'");
if ( mysql_num_rows($query) >= 1 )
   {
   echo 'Existed !';
   }
else
   {
   echo 'Not existed , making :';
   $query = mysql_query('insert into `table` values ( "11", ... )');
   }
?>
于 2013-06-25T09:38:23.713 に答える
0

これを試して

if not exists(select top 1 id from some table Where id = @someid)
begin
  insert sometable(id) Values (@id)
end
else
begin
 -- do something
end
于 2013-06-25T10:10:18.027 に答える