Hello I have got this following statement that I would like it to INSERT INTO if there wasn't found any value with id = 1
If it exist I would like to update
I inspired by this:
UPDATE Table1 SET (...) WHERE Column1='SomeValue'
IF @@ROWCOUNT=0
INSERT INTO Table1 VALUES (...)
But getting this Exception: Incorrect syntax near (.
But I cant find where do I make a mistake , would someone help me solve this out please?
string sqlcom = "UPDATE firma SET (firma=@firma,ulice=@ulice,mesto=@mesto,psc=@psc,ico=@ico,dico=@dico,dph=@dph,sdph=@sdph,upo1=@upo1,raz1=@raz1) WHERE id='1' IF @@ROWCOUNT=0 INSERT INTO firma (firma,ulice,mesto,psc,ico,dico,dph,sdph,upo1,raz1) VALUES (@firma,@ulice,@mesto,@psc,@ico,@dico,@dph,@sdph,@upo1,@raz1)";
SqlCommand prikaz =
new SqlCommand(sqlcom, spojeni);
prikaz.Parameters.AddWithValue("@firma", ffirma.Text);
prikaz.Parameters.AddWithValue("@ulice", fulice.Text);
prikaz.Parameters.AddWithValue("@mesto", fmesto.Text);
prikaz.Parameters.AddWithValue("@psc", fpsc.Text);
prikaz.Parameters.AddWithValue("@ico", fico.Text);
prikaz.Parameters.AddWithValue("@dico", fdico.Text);
prikaz.Parameters.AddWithValue("@dph", fdph.Text);
prikaz.Parameters.AddWithValue("@sdph", fsdph.Text);
prikaz.Parameters.AddWithValue("@raz1", fraz1.Text);
prikaz.Parameters.AddWithValue("@upo1", fupo1.Text);
spojeni.Open();
prikaz.ExecuteNonQuery();
spojeni.Close();
(and)around the values in yourSETblock - i.e.,SET firma=@firma,ulice=@ulice,..