Connecting Tech Pros Worldwide Forums | Help | Site Map

How to send an IF statement by a Transaction

Newbie
 
Join Date: Apr 2009
Location: Stuttgart, Germany
Posts: 28
#1: Jun 16 '09
Hi guys,

how can I send an IF statement by T-SQL?

Lets suppose that I want to insert something, for example;

Expand|Select|Wrap|Line Numbers
  1. int n_count = 5;
  2. string querytosend = @"if  (" + n_count + " > 0)
  3.      INSERT persons (name, age, address) values ('raul', 23, 'Könnigstraße 23')";
  4.  
the if statements change regarding the DB engine, I have installed MySQL Server 2005, when I send transactions the server version is 5.0.67-community-nt. I think that's why I get and 1064 Code Error. If you could advise me somehow I will appreciate so much.

Raul Bolaños,
Best regards.

Newbie
 
Join Date: Apr 2009
Location: Stuttgart, Germany
Posts: 28
#2: Jun 16 '09

re: How to send an IF statement by a Transaction


Quote:

Originally Posted by raulbolanos View Post

Hi guys,

how can I send an IF statement by T-SQL?

Lets suppose that I want to insert something, for example;

Expand|Select|Wrap|Line Numbers
  1. int n_count = 5;
  2. string querytosend = @"if  (" + n_count + " > 0)
  3.      INSERT persons (name, age, address) values ('raul', 23, 'Könnigstraße 23')";
  4.  
the if statements change regarding the DB engine, I have installed MySQL Server 2005, when I send transactions the server version is 5.0.67-community-nt. I think that's why I get and 1064 Code Error. If you could advise me somehow I will appreciate so much.

Raul Bolaños,
Best regards.

I cant make this work... please help me.

Expand|Select|Wrap|Line Numbers
  1. int x = 23;
  2. string queryString = @"CASE WHEN (" + x + @" > 0)
  3.                                      THEN UPDATE person SET person.age = 23 WHERE age = 22
  4.                                      ELSE 'x is less than 0'
  5.                                    END";
  6.  
PRR PRR is offline
Moderator
 
Join Date: Dec 2007
Location: India
Posts: 702
#3: Jun 16 '09

re: How to send an IF statement by a Transaction


You will have to go through the syntax of t-sql statements .
Link
MSDN
Newbie
 
Join Date: Apr 2009
Location: Stuttgart, Germany
Posts: 28
#4: Jun 16 '09

re: How to send an IF statement by a Transaction


Quote:

Originally Posted by DeepBlue View Post

You will have to go through the syntax of t-sql statements .
Link
MSDN

The problem is that I have found only examples where whether the IF or CASE..WHEN statements are inside the Query. And I need to apply them outside.
Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#5: Jun 17 '09

re: How to send an IF statement by a Transaction


You don't need to send an if to T-SQL at all. You have all value of n in your C# code, test it there using C# and run the insert only if your required conditions are met.
You use an IF in T-SQL only if the arguments to the IF are themselves coming from the database.
Reply