How to covert INT to VARCHAR in SQL condition
18,871
Solution 1
Try this:
select... from... where cast(R.WORK_YM as varchar(10))= '201611'
Solution 2
Try this Query for SQL Server,
Use CONVERT
function
select * from Table R where CONVERT(varchar(10), R.WORK_YM) = '201611'
OR
Use STR
function
select * from Table R where STR(R.WORK_YM,10) = '201611'
OR
Use CAST
function
select * from Table R where CAST(R.WORK_YM as varchar(10)) = '201611'
For MySQL,
Use CAST
function
select * from Table R where CAST(R.WORK_YM as Char(10)) = '201611'
Use CONVERT
function
select * from Table R where CONVERT(Char(10), R.WORK_YM) = '201611'
Author by
Dang Anh
Updated on June 07, 2022Comments
-
Dang Anh almost 2 years
select... from... where R.WORK_YM = 201611
how to change R.WORK_YM to String value?
-
Dang Anh over 7 yearsIt's not work for my sql and here is the error: [Error Code: -461, SQL State: 42846] DB2 SQL error: SQLCODE: -461, SQLSTATE: 42846, SQLERRMC: SYSIBM.INTEGER;SYSIBM.VARCHAR ..
-
Dang Anh over 7 yearsI tried every query you posted but it's still not work and the error is: Error Code: -461, SQL State: 42846] DB2 SQL error: SQLCODE: -461, SQLSTATE: 42846, SQLERRMC: SYSIBM.INTEGER;SYSIBM.VARCHAR
-
Ranjana Ghimire over 7 yearsIts for mssql . Try this for mysql : select... from... where cast(R.WORK_YM as char(10))= '201611'
-
Dang Anh over 7 yearsmy job is doing on mssql Beauty!
-
Ranjana Ghimire over 7 yearsDid the next query work?
-
Dang Anh over 7 yearsYES! IT WORKS, THANK YOU xD
-
Dang Anh over 7 yearsno worries , I got the answer from Ranjana Ghimire: where cast(R.WORK_YM as char(10))= '201611' Thank you!
-
Ranjana Ghimire over 7 yearsCan you please submit my comment as answer :)
-
Kushan over 7 yearsohh you are using mysql. ok great