|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
|
run an if statement within a query
Hi all;
I have searched the net for the following but am not too sure how it's done. I am trying to create an if statement within a sql query where based on the results it will stop or continue something like: count(*) from test_table where test_column = 0 go if result = 0 then ALTER TABLE test_table DROP COLUMN test_column go select into test_table_2 from test_table go and so on and so forth any will help will be apprecated thanks |
|
#2
|
|||
|
|||
|
If you are using T-SQL I suggest either using a BEGIN and END block or a procedure.
__________________
El éxito consiste en una serie de pequeñas victorias día a día MySQL, MS SQL, MS ACCESS, Oracle Database Manager - http://victorpendleton.net/products/psdviewer.html |
|
#3
|
|||
|
|||
|
Here's the basic idea...
Code:
If [expression to be eval'd here]
BEGIN
[sql statements you want to do if expression is true]
END
Is this somewhat close to what you're looking for? Code:
if (select count(*) from test_table where test_column = 0) = 0 BEGIN ALTER TABLE test_table DROP COLUMN test_column select into test_table_2 from test_table END More info on IF statement here Last edited by Username=NULL : August 27th, 2004 at 09:37 PM. |
|
#4
|
|||
|
|||
|
thanks username=null
thats exactly what I'm looking for
|
![]() |
| Viewing: Dev Shed Forums > Databases > MS SQL Development > run an if statement within a query |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|