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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Joining Columns

Author  Topic 

kbnyny
Starting Member

4 Posts

Posted - 2012-05-24 : 12:59:08
I have two columns same db, different tables, one is varchar( S 12345) and the other is int (12345).
I want to join the tables using these columns I don't need to used the (S)
Is there a way to do this if so how can it be done.

Joining the tables I get an error Syntax error converting the varchar value 's 12345' to a column of data type int.

Thanks

robvolk
Most Valuable Yak

15732 Posts

Posted - 2012-05-24 : 13:03:15
SELECT * FROM Table1 A
INNER JOIN Table2 B ON A.ID=CAST(REPLACE(B.ID,'S ','') AS int)
Go to Top of Page

kbnyny
Starting Member

4 Posts

Posted - 2012-05-24 : 14:46:07
Thank you very much is work perfect.
Go to Top of Page

kbnyny
Starting Member

4 Posts

Posted - 2012-05-24 : 17:19:56
Now I have another issue I'm receiving this error "Syntax error converting the varchar value 'u46107' to a column of data type int."

How do I add another cast (replace b.id, 'U' to the below statement?
Found out there is an S and U that I don't need.

SELECT * FROM
Table1 A
INNER JOIN Table2 B ON A.ID=CAST(REPLACE(B.ID,'S ','') AS int)

Thanks
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2012-05-25 : 07:36:26
SELECT * FROM
Table1 A
INNER JOIN Table2 B ON A.ID=CAST(REPLACE(REPLACE(B.ID,'S ',''),'u','') AS int)
Go to Top of Page

kbnyny
Starting Member

4 Posts

Posted - 2012-05-25 : 10:03:34
Work perfectly

Thank you
Go to Top of Page

zohanel
Starting Member

7 Posts

Posted - 2012-05-31 : 16:33:47
but for this problem

Helo i have a probleme here from the table Character Coloana PCPointsi have players that paly o this game and win PCPoints letz say 100 and i want to make a php or a SQL JOB i wood like Php , this PCPoints in Tabel MEMB_INFO Coloana cspoints but after i conver them i want to be like this
before conversion PCPoints = 100 cspoints = 0
after Pcpoints = 0 cspoints =100
here are my tables Tabelele


Character MEMB_INFO

i have try to make this code via the book but is not working i mess up i have made a progres but the PCPoints did not delete after conversion
Update MEMB_INFO Set cspoints = a.cspoints+b.PCPoints FROM Character iner JOIN MEMB_STAT ON Character.AccountID=MEMB_INFO.memb___id where a=cspoints and b=PCPoints

is verry immportant after the conversion the player have 0 PCPoints , because i dont want them to update the cspoints forever
Go to Top of Page
   

- Advertisement -