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 |
cplusplus
Aged Yak Warrior
567 Posts |
Posted - 2013-12-09 : 06:29:45
|
I have two columns(filepath, archivepath) in same table / row holding two different file paths, primary key is docid.I want to show as two rows.Doctype is just a flag to show whther it is type F or A and first three columns has same value in table.docid,modrecordid, modname, filepath as docpath, 'F' as DocTypedocid,modrecordid, modname, archivepath as docpath, 'A', as DocTypeUsing Base query getting above 5 column values, every docid with rows:select docid, modrecordid, modName, filepath, archivepath from tab_docrepository order by docid;Thank you very much for the helpful info. |
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2013-12-09 : 07:13:40
|
select docid,modrecordid, modname, filepath as docpath, 'F' as DocType from tableunion allselect docid,modrecordid, modname, archivepath as docpath, 'A' as DocType from table Too old to Rock'n'Roll too young to die. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-12-09 : 07:23:23
|
[code]select t.docid,t.modrecordid, t.modname,t1.docpath,t1.DocTypefrom table tcross apply (values(t.filepath,'F'),(t.archivepath,'A'))t1(docpath,DocType)[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
cplusplus
Aged Yak Warrior
567 Posts |
Posted - 2013-12-09 : 13:57:36
|
Visakh, I like your approach using cross apply. Thank you very much for the help. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-12-09 : 22:28:37
|
quote: Originally posted by cplusplus Visakh, I like your approach using cross apply. Thank you very much for the help.
you're welcomeVALUES is table constructor available from 2008 onwards and you can use it for following scenarioshttp://visakhm.blogspot.in/2012/05/multifacet-values-clause.html------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
|
|
|
|
|