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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Compare of two columns

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: one

In
-----------
C-1425
ASBI/1110060337
C-1396
C-1354
C-1326
C-1304


table2 : two

Code IN
---------- --------
A52H00110 453/C-1396

C30K00140 453/C-1396
A50H00040 455/C-1425
C82J02140 455/C-1425


in 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: one

In
-----------
C-1425
C-1396
C-1354
C-1326
C-1304


table2 : two

Code
----------
A52H00110
C30K00140
A50H00040
C82J02140
---------


IN
--------
453/C-1396
453/C-1396
455/C-1425
455/C-1425


in 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
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-22 : 04:29:04
[code]SELECT *
FROM Table1 t1
JOIN Table2 t2
ON t1.IN=SUBSTRING(t2.IN,CASE WHEN CHARINDEX('/',t2.IN)>0 THEN CHARINDEX('/',t2.IN)+1 ELSE 1 END,LEN(t2.IN))[/code]
Go to Top of Page

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
Go to Top of Page

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)
Go to Top of Page

Leo_Don
Starting Member

42 Posts

Posted - 2008-10-22 : 06:17:35
HI Visakh,

I wanted only the month and year of the column

DATE
-------
31-02-2007
21-03-2007

and the reslt colum shold be like

DATE
----------
02-2007
03-2007

thank you
Go to Top of Page

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 column

DATE
-------
31-02-2007
21-03-2007

and the reslt colum shold be like

DATE
----------
02-2007
03-2007

thank you



SELECT RIGHT(CONVERT(varchar(10),datecol,105),7)
Go to Top of Page

Leo_Don
Starting Member

42 Posts

Posted - 2008-10-22 : 06:44:57
Thanx visakh

its works all good
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-22 : 06:45:43
quote:
Originally posted by Leo_Don

Thanx visakh

its works all good


cheers
Go to Top of Page
   

- Advertisement -