Naitik Gamit
asked on
Convert Nverchar Value Contain Comma To Int In SQL
I have Nvarchar Value As '7055,7085,7090,7035,7040, 7050,7053, 7055'
I Want To Convert It To Int.
Using Cast Or Convert It throw Error As Conversion failed when converting the nvarchar value '7010,7035,7045,7050,7053, 7055,7085, 7090,7040' to data type int.
Help Me To Convert It To Int
Thank You.
I Want To Convert It To Int.
Using Cast Or Convert It throw Error As Conversion failed when converting the nvarchar value '7010,7035,7045,7050,7053,
Help Me To Convert It To Int
Thank You.
What do you pretend to do? Split each number in the varchar field and convert it one by one to int?
ASKER
I want to use this converted int value to IN query as
Select A,B,C Fom Etc_Tbl Where ID IN ( )
When I am using nvarchar value it throw error as :
Conversion failed when converting the nvarchar value '7010,7035,7045,7050,7053, 7055,7085, 7090,7040' to data type int.
I am also try cast and convert but no change......
Select A,B,C Fom Etc_Tbl Where ID IN ( )
When I am using nvarchar value it throw error as :
Conversion failed when converting the nvarchar value '7010,7035,7045,7050,7053,
I am also try cast and convert but no change......
Etc_Tbl is INT data type?
And what is the column name for you varchar values?
And what is the column name for you varchar values?
ASKER
yes............
Select A,B,C Fom Etc_Tbl Where ID IN ( )
In my query ID is int and nvarchar field is named Role_CSV
so,i am trying as
Select A,B,C Fom Etc_Tbl Where ID IN ( Role_CSV )
Select A,B,C Fom Etc_Tbl Where ID IN (CAST(Role_CSV AS INT ) )
Select A,B,C Fom Etc_Tbl Where ID IN (CONVERT(INT,Role_CSV ) )
But it not convert Role_CSV to INT.
Select A,B,C Fom Etc_Tbl Where ID IN ( )
In my query ID is int and nvarchar field is named Role_CSV
so,i am trying as
Select A,B,C Fom Etc_Tbl Where ID IN ( Role_CSV )
Select A,B,C Fom Etc_Tbl Where ID IN (CAST(Role_CSV AS INT ) )
Select A,B,C Fom Etc_Tbl Where ID IN (CONVERT(INT,Role_CSV ) )
But it not convert Role_CSV to INT.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Try to think in another solution as for example why not to convert the INT column to VARCHAR and compare it in the WHERE clause:
Select A,B,C
From Etc_Tbl
WHERE Role_CSV LIKE '%'+CAST(ID AS VARCHAR)+'%'
select a, b, c from etc_tbl
where charindex(cast(id as varchar(20)),'7040,7055,70 90,7035,70 40,7050,70 53,7055') > 0
where charindex(cast(id as varchar(20)),'7040,7055,70