sql server - TSQL Select Clause with Case Statement -


i have basic select statement getting me list of types stored in database:

select tetype   bs_trainingevent_types source = @source    xml path ('options'), type, elements, root ('types') 

my table contains type column , source column.

there record in table need include 2 separate sources can't create separate record it.

**table  data**  type   |  source    test      users test2     members test3     admins 

i need case statement able if source = admins give me type test2.

does make sense , possible basic select?

update came temp solution still think there better way handle this.:

declare @tmp table ( qid varchar (10));  insert @tmp (qid) select distinct qid   tfs_adhocpermissions;  select t.qid,        emp.firstname,        emp.lastname,        emp.ntid,        (select accesskey           tfs_adhocpermissions p          p.qid = t.qid            xml path ('key'), type, elements, root ('keys'))   @tmp t        left outer join        dbo.employeetable emp        on t.qid = emp.qid    xml path ('data'), type, elements, root ('root'); 

try this

-------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --create temp table testing if object_id('tempdb..#bs_trainingevent_types') not null      drop table #bs_trainingevent_types select  [type] ,         [source]    #bs_trainingevent_types    ( values ( 'test', 'users'), ( 'test2', 'members'),         ( 'test3', 'admins') ) t ( [type], [source] )  -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --final query declare @source varchar(10) = 'users'  if @source = 'admins'      begin         select  [type]            #bs_trainingevent_types           source = @source                 or [type] = 'test2'             xml path('options') ,                     type ,                     elements ,                     root('types')     end else      begin         select  [type]            #bs_trainingevent_types           source = @source             xml path('options') ,                     type ,                     elements ,                     root('types')      end 

Comments

Popular posts from this blog

Java 8 + Maven Javadoc plugin: Error fetching URL -

css - SVG using textPath a symbol not rendering in Firefox -

order - Notification for user in user account opencart -