Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Hot to make a string with this Query?

Author  Topic 

raulbolanos
Starting Member

6 Posts

Posted - 2009-06-16 : 08:49:29
Hi guys,

I need to make a query with this algorythm whithin one single String.

IF X < 18
Start
DELETE from School WHERE age = 17;
DELETE from Party WHERE hobby = 'alcohol';
DELETE from Girls WHERE hair = 'blodes';
End
INSERT School (age, name) VALUES(17, 'RaiL');
INSERT Party (drink, name) VALUES('soda', 'RaiL');
INSERT Girls (girls, name) VALUES('none', 'RaiL');

Any idea?

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-06-16 : 08:55:24
[code]IF @x < 18
BEGIN
DELETE from School WHERE age = 17
DELETE from Party WHERE hobby = 'alcohol'
DELETE from Girls WHERE hair = 'blodes'
END

INSERT School (age, name) VALUES(17, 'RaiL')
INSERT Party (drink, name) VALUES('soda', 'RaiL')
INSERT Girls (girls, name) VALUES('none', 'RaiL')[/code]


E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

raulbolanos
Starting Member

6 Posts

Posted - 2009-06-16 : 09:18:25
I already try that, but I get an 1064 Error :(
Go to Top of Page

raulbolanos
Starting Member

6 Posts

Posted - 2009-06-16 : 09:19:32
by the way, every different Query need a semicolon ';' at the end? in this case we need 6.
Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2009-06-16 : 09:41:33
1064 error? Something like:
"
You have an error in your SQL syntax; check the manual that corresponds to your MySQL
server version for the right syntax to use near...."

Are you using MySql?


Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page
   

- Advertisement -