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 |
|
Nylren
Starting Member
7 Posts |
Posted - 2011-02-19 : 18:42:08
|
Hi, guys,I cant figure out how to solve this sql. Please, assist me :)THANKSselect (case when count(*) = 1 then Url else select t2.Url from Site t2 where t2.ID = 2 and t2.Nome = 'PackUrl' end) Urlfrom Site twhere t.ID = 2 |
|
|
mmarovic
Aged Yak Warrior
518 Posts |
Posted - 2011-02-20 : 06:12:40
|
| Not sure what are you trying to achieve. It looks like you want to display the only url of site specified. In case there are multiple urls from the site you want to display one named 'PackUrl'. However, what if there are multiple urls and there is no one named 'PackUrl'?MirkoMy blog: http://mirko-marovic-eng.blogspot.com/ |
 |
|
|
Nylren
Starting Member
7 Posts |
Posted - 2011-02-20 : 09:02:44
|
| You got the logic right! That's exactly what I need.When inserting a new site, if there is more than 1 Url, the admin needs to enter the PackUrl.Please, help me out |
 |
|
|
mmarovic
Aged Yak Warrior
518 Posts |
Posted - 2011-02-21 : 15:10:47
|
Assuming there is never more then one "PackUrl":select MAX(case when s.url is null then t.url else s.url end ) URLfrom Site tleft join site s on t.id = s.id and s.nome = 'PackUrl'where t.ID = 2 MirkoMy blog: http://mirko-marovic-eng.blogspot.com/ |
 |
|
|
|
|
|