473,396 Members | 1,671 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to send an IF statement by a Transaction

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.
Jun 16 '09 #1
4 1403
@raulbolanos
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.  
Jun 16 '09 #2
PRR
750 Expert 512MB
You will have to go through the syntax of t-sql statements .
Link
MSDN
Jun 16 '09 #3
@DeepBlue
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.
Jun 16 '09 #4
r035198x
13,262 8TB
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.
Jun 17 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: ryan.mclean | last post by:
Hi all, first, let me preface this by saying that I am very new to sql server, coming from oracle. Here is my problem: I would like to have a case statement (similar to decode in oracle) that...
1
by: JT | last post by:
can someone point me in the right direction for learning more about how to go about sending a batch of sql statements from asp to sql server, and having errors appropriately handled? for...
8
by: Dot Net Newbie | last post by:
New to DOTNET so please be gentle: I have an in-memory dataset that I want move to a SQL Server database. The XML schema with which the dataset was built matches exactly the table schema in SQL...
19
by: Steve | last post by:
ASP error number 13 - Type mismatch with SELECT...FOR UPDATE statement I got ASP error number 13 when I use the SELECT...FOR UPDATE statement as below. However, if I use SELECT statement without...
2
by: John | last post by:
The ASP application inserts transaction records in transaction table with the system time as the primary key. However, it is possible to have primary key violation because the records in...
6
by: Twobridge | last post by:
I hope someone can help me out with my problem. I have found a sql statement that basically pulls all bills filed within a certain time period and the payments made on those bills with in the...
4
by: Joseph Geretz | last post by:
We use a Soap Header to pass a token class (m_Token) back and forth with authenticated session information. Given the following implementation for our Logout method, I vastly prefer to simply code...
4
Zwoker
by: Zwoker | last post by:
Hi all, I'm not sure whether this should be posted in the MS Access forum or one of the SQL forums (which one?), so I'll start here. I'm self taught in the syntax of SQL based queries that I...
4
by: gurufordy | last post by:
Hello. Trying to use the ASP.net user functionality but it keeps failing on me. I have created a login and registration page for my site. When you fill in the registration form it should send a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.