Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
Hi, I have the following query that feeds a dropdown menu for all users of table plantilla. The parameter @SelectUserName is supposed to be the current user, and I want him to be on top of the list; then there comes a separation line and then all possible users. There are cases when the current user is not part of plantilla and therefore @SelectUserName is NULL. In this case I dont want the separtion lines to appear. How could I do this?
select nombre_con, @SelectUserName as USERID from plantilla where userid =Replace(@SelectUserName, 'CORP\','') union all select '---', '---' union all select a.nombre_con, 'CORP\'+a.userid from (select top 100 nombre_con, userid from plantilla WHERE EMPLID IS NOT NULL order by nombre_con)a
Any suggestions?Martin
bitsmed
Aged Yak Warrior
545 Posts
Posted - 2013-06-09 : 16:37:54
Reuse your from/where code, like this:
select nombre_con, @SelectUserName as USERID from plantilla where userid =Replace(@SelectUserName, 'CORP\','')union all select '---', '---' from plantilla where userid =Replace(@SelectUserName, 'CORP\','')union all select a.nombre_con, 'CORP\'+a.userid from (select top 100 nombre_con, userid from plantilla WHERE EMPLID IS NOT NULL order by nombre_con)a
barnabeck
Posting Yak Master
236 Posts
Posted - 2013-06-09 : 17:44:49
off course... how could I not get this!!Thank you very much!!
visakh16
Very Important crosS Applying yaK Herder
52326 Posts
Posted - 2013-06-10 : 08:04:39
isnt this enough?
select nombre_con + CHAR(10) + CHAR(13) + '-------------', @SelectUserName + CHAR(10) + CHAR(13) + '-------------' from plantilla where userid =Replace(@SelectUserName, 'CORP\','')union all select a.nombre_con, 'CORP\'+a.userid from (select top 100 nombre_con, userid from plantilla WHERE EMPLID IS NOT NULL order by nombre_con)a
------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs