sql - Format Query Results using Cross join -


so i'm still new cross joins, use them. able find answer first part of problem, not second.

i've got results output in layout want, here results

+-----------+-----------+-------------------------+ | full name | cert_type |       expiration        | +-----------+-----------+-------------------------+ | jane doe  |         1 | 2015-09-26 00:00:00.000 | | jane doe  |         2 | 2015-04-21 00:00:00.000 | | jane doe  |         3 | 2015-12-16 00:00:00.000 | | john doe  |         1 | 2016-10-06 00:00:00.000 | | john doe  |         2 | 2015-04-19 00:00:00.000 | | john doe  |         3 | 2011-04-12 00:00:00.000 | +-----------+-----------+-------------------------+ 

here query well:

select     [full name],      cert_type = x.which,     expiration  =         case x.which         when '1' [license exp date]         when '2' [med cert exp date]         when '3' [annual mvr review due]         end employee_data.dbo.employeedatabase cross join (select '1' union select '2' union select '3') x (which) [license exp date] between getdate() , dateadd(dd, 7, getdate()) or [med cert exp date] between getdate() , dateadd(dd, 7, getdate()) or [annual mvr review due] between getdate() , dateadd(dd, 7, getdate()) , [termination date] null 

as can see where clause still in place, it's pulling every date, , i"m wanting dates within given ranges inside where clause. want dates output if set them output(varchar(10), date, 101)

if there further questions please let me know, keep working on here. thank receive!

something this. should in habit of using name of datepart instead of abbreviation. difficult remember , using name clear. http://sqlblog.com/blogs/aaron_bertrand/archive/2011/09/20/bad-habits-to-kick-using-shorthand-with-date-time-operations.aspx

with mycte (     select         [full name],          cert_type = x.which,         expiration  =             case x.which             when '1' [license exp date]             when '2' [med cert exp date]             when '3' [annual mvr review due]             end     employee_data.dbo.employeedatabase     cross join (select '1' union select '2' union select '3') x (which)     [license exp date] between getdate() , dateadd(dd, 7, getdate())     or [med cert exp date] between getdate() , dateadd(dd, 7, getdate())     or [annual mvr review due] between getdate() , dateadd(dd, 7, getdate())     , [termination date] null )  select * mycte expiration between getdate() , dateadd(day, 7, getdate()) 

Comments

Popular posts from this blog

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

Java 8 + Maven Javadoc plugin: Error fetching URL -

order - Notification for user in user account opencart -