this :にA
列 sayid
と属性を持つテーブルがあります。特定の列を検索して11などのアクションを実行するような方法でSQLクエリが必要です。それ以外の場合は、その(11)値を持つ新しい行を挿入します。id
1 to 20 or any others
Query
id
要するに
Search 11 in id if found then update 11 to 12 otherwise insert 11 into id
this :にA
列 sayid
と属性を持つテーブルがあります。特定の列を検索して11などのアクションを実行するような方法でSQLクエリが必要です。それ以外の場合は、その(11)値を持つ新しい行を挿入します。id
1 to 20 or any others
Query
id
要するに
Search 11 in id if found then update 11 to 12 otherwise insert 11 into id
if not exists(select id from some table Where id = @someid)
begin
insert sometable(id) Values (@id)
end
else
begin
/* do something else */
end
複雑にしないでおく...
を使用し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
あなたのリクエストにクエリがあるかどうかはわかりませんが、 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", ... )');
}
?>
これを試して
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