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.
| Author |
Topic |
|
brace77
Starting Member
25 Posts |
Posted - 2009-07-17 : 09:21:03
|
| I need to run some scripts where I start by checking some conditions and only if they are satisified I proceed.Someting like:if (Boolean condition)BEGINstatement 1statement 2...statement NENDThis works in general, but doesn't work with ALTER VIEWIt works if I use EXEC('ALTER VIEW...') but this is an apporoach that I don't like.Is there a way to do this?An alternative could be if not (Boolean condition) BREAK/EXIT/STOPand totally EXIT the script at that point... |
|
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2009-07-17 : 12:20:50
|
| you want to conditionally alter the view? or you want if/else logic inside the view?maybe you can post what you have, and we can help you fix it. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-07-17 : 13:54:43
|
| seems like what you need is a case expression inside view definition |
 |
|
|
brace77
Starting Member
25 Posts |
Posted - 2009-07-17 : 15:31:44
|
| I use scripts for managing my application database.I number scripts from 1 to N.When I run script N I check that in a table where I keep scripts history there is an entry for script N-1 (that means N-1 was succesful).So I want t doif EXISTS ("SELECT record N-1 in table")begin MY NEW SCRIPT CONTAINING ALTER VIEWendOf course I could handle in other places this logic (like in the application that runs the scripts, but I wanted to add this ectra layer of security, so I am sue one doesn't accidentaly run a script if previous was not run.Since this scripts can be also run manually, it is better to help people not to run them in the wrong order.This is why I need this if...else. It is just for Do ALL or DO nothing. If there is a better way pease suggest! |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2009-07-17 : 15:51:09
|
I really know what you want but in T-SQL it is not possible without stumbling from trap to trap.Whe have build an app to handle this and it is much much better to handle. No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
brace77
Starting Member
25 Posts |
Posted - 2009-07-21 : 03:41:58
|
quote: Originally posted by webfred I really know what you want but in T-SQL it is not possible without stumbling from trap to trap.Whe have build an app to handle this and it is much much better to handle. No, you're never too old to Yak'n'Roll if you're too young to die.
Thanks a lot, so it is clear that I will do the same. I have an application that with a small modification can handle this, the bad thing is that if scripts are run manually I have no way to put an extra security check "embedded" in the script. |
 |
|
|
|
|
|