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 |
|
rsvore
Starting Member
15 Posts |
Posted - 2012-04-13 : 10:56:29
|
| This si a simple if nested with another if bu tI can't get the second select to run when I test it. I'm sure I have the Begin and End mixed up. Any ideas? Thanks.If @inOp = 1BeginIf @u_admin ='T' or @u_id = 69 or @u_id = 68 Beginselect cc,country_na from cc_code order by country_naEndENDElseBeginIf @u_id=79select ttl_data.cc,cc_code.country_na from cc_code,ttl_data where est_fy>'1999' AND cc_code.cc=ttl_data.cc and ttl_data.loc in(select loc_code from imso_loc where user_id=@u_id) group by ttl_data.cc,cc_code.country_na order by country_naENDEND |
|
|
rsvore
Starting Member
15 Posts |
Posted - 2012-04-13 : 10:58:16
|
| I think I just found it the END at teh top needed to be moved to the bottom.If @inOp = 1BeginIf @u_admin ='T' or @u_id = 69 or @u_id = 68 Beginselect cc,country_na from cc_code order by country_naEndElseBeginIf @u_id=79select ttl_data.cc,cc_code.country_na from cc_code,ttl_data where est_fy>'1999' AND cc_code.cc=ttl_data.cc and ttl_data.loc in(select loc_code from imso_loc where user_id=@u_id) group by ttl_data.cc,cc_code.country_na order by country_naENDENDEND |
 |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2012-04-13 : 11:17:51
|
Rsvore already gave teh answer, but I just wanted to add that formatting can go a long way to help undersand the code and see issues like this. You didn't use teh code tags when posting, so hard to say if you had it formatted originally or not. However, I did some basic formatting and you can see how the BEGIN-END pairs match up:If @inOp = 1Begin -- #1 If @u_admin ='T' or @u_id = 69 or @u_id = 68 Begin -- @#2 select cc,country_na from cc_code order by country_na End -- #2END -- #1ElseBegin -- #3 If @u_id=79 select ttl_data.cc, cc_code.country_na from cc_code, ttl_data where est_fy>'1999' AND cc_code.cc=ttl_data.cc and ttl_data.loc in ( select loc_code from imso_loc where user_id=@u_id ) group by ttl_data.cc, cc_code.country_na order by country_naEND -- #3END --#?? |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-04-13 : 11:28:07
|
| [code]select coalesce(ttl_data.cc,cc_code.cc) as cc, cc_code.country_na from cc_code left join ttl_data on est_fy>'1999' AND cc_code.cc=ttl_data.cc and ttl_data.loc in ( select loc_code from imso_loc where user_id=@u_id ) where ((@u_id=79 and ttl_data.cc is not null ) or @u_admin ='T' or @u_id in (69,68)) group by coalesce(ttl_data.cc,cc_code.cc), cc_code.country_na order by country_na[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|
|
|