sql server - Use of UNION enables more powerful SQL constructions -


i think shame op deleted question, poorly worded , phrased was; provides opportunity demonstrate use of union operation in sql dynamically construct relations needed perform operations efficiently:
original post (i attribute source if op comments below requesting it):

i have 2 tables called tblbooking , tblroom
tblbooking has id, day, roomid;
tblroom has id, description

i need create query shows rooms arent in use on days, ie 1,2,3,4,5,6,7

how can using union query? have tried different combinations, cant work, please help

in sql server 2008+, can use table-value constructors:

select day, roomid (values (1),(2),(3),(4),(5),(6),(7)) days(day)  cross join tblroom except select day, roomid tblbooking order roomid, day 

http://www.sql-server-helper.com/sql-server-2008/row-value-constructor-as-derived-table.aspx http://msdn.microsoft.com/en-us/library/dd776382.aspx


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

javascript - Clean way to programmatically use CSS transitions from JS? -

android - send complex objects as post php java -