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 |
amurark
Yak Posting Veteran
55 Posts |
Posted - 2012-12-20 : 09:44:59
|
Hi Pls tell me There are two tables A and B where asset tags are present, but in one table in rows and in another in column wise.for eg ASSet TagSR-062009-00032966 SR-062009-00032962SR-072009-00020572SR-072009-00020571SR-072009-00020585HH-092009-00038342Table B Asset TAGSR-072009-00020572,SR-072009-00020571,SR-062009-00020685,SR-072009-00001592,SR-072009-00001376,SR-062009-00020683,SR-092009-00001617pls tell me the query so that asset tag of A matches with each and every asset tag table of B and output comes as OutputSR-062009-00032966 SR-062009-00032962SR-072009-00020572SR-072009-00020571SR-072009-00020585Ankita |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-12-20 : 11:01:11
|
two methods1. using string comparison techniqueSELECT a.*FROM tableA aINNER JOIN tableB bWHERE ',' + b.AssetTAG + ',' LIKE '%,' + a.AssetTAG + ',%'2. use a string splitting UDF and then joinSELECTFROM(SELECT f.ValFROM tableB bCROSS APPLY dbo.ParseValues(b.AssetTAG,',') f)mINNER JOIN TableA aON a.AssetTAG = m.ValParseValues can be found in below linkhttp://visakhm.blogspot.in/2010/02/parsing-delimited-string.html ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
|
|
|
|
|