| Author |
Topic |
|
Leo_Don
Starting Member
42 Posts |
Posted - 2008-10-22 : 04:24:12
|
| Hi Experts,I wold like to compare two colums of diffrent tables and disply the values table1: oneIn-----------C-1425ASBI/1110060337C-1396C-1354C-1326C-1304table2 : twoCode IN ---------- --------A52H00110 453/C-1396C30K00140 453/C-1396A50H00040 455/C-1425C82J02140 455/C-1425in the above tables i want the values of the IN colums to be compare . i.e the colum "in" value of table one to be compare with the colum "in" vaule of table two after the "/" and display the code column thanx in advance |
|
|
Leo_Don
Starting Member
42 Posts |
Posted - 2008-10-22 : 04:27:59
|
| Hi Experts,I wold like to compare two colums of diffrent tables and disply the values table1: oneIn-----------C-1425C-1396C-1354C-1326C-1304table2 : twoCode ---------- A52H00110 C30K00140 A50H00040 C82J02140 ---------IN --------453/C-1396453/C-1396455/C-1425455/C-1425in the above tables i want the values of the IN colums to be compare . i.e the colum "in" value of table one to be compare with the colum "in" vaule of table two after the "/" and display the code columnthanx in advance |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-10-22 : 04:29:04
|
| [code]SELECT *FROM Table1 t1JOIN Table2 t2ON t1.IN=SUBSTRING(t2.IN,CASE WHEN CHARINDEX('/',t2.IN)>0 THEN CHARINDEX('/',t2.IN)+1 ELSE 1 END,LEN(t2.IN))[/code] |
 |
|
|
Leo_Don
Starting Member
42 Posts |
Posted - 2008-10-22 : 06:01:25
|
| Thank you...It works fine...and one more request,how can i get only month and year from the date column |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-10-22 : 06:08:01
|
quote: Originally posted by Leo_Don Thank you...It works fine...and one more request,how can i get only month and year from the date column
Use DATEPART(mm,col),DATEPART(yy,col)or use MONTH(col) & YEAR(col) |
 |
|
|
Leo_Don
Starting Member
42 Posts |
Posted - 2008-10-22 : 06:17:35
|
| HI Visakh,I wanted only the month and year of the columnDATE-------31-02-200721-03-2007and the reslt colum shold be likeDATE----------02-200703-2007thank you |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-10-22 : 06:28:31
|
quote: Originally posted by Leo_Don HI Visakh,I wanted only the month and year of the columnDATE-------31-02-200721-03-2007and the reslt colum shold be likeDATE----------02-200703-2007thank you
SELECT RIGHT(CONVERT(varchar(10),datecol,105),7) |
 |
|
|
Leo_Don
Starting Member
42 Posts |
Posted - 2008-10-22 : 06:44:57
|
Thanx visakhits works all good |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-10-22 : 06:45:43
|
quote: Originally posted by Leo_Don Thanx visakhits works all good
cheers |
 |
|
|
|