I have the following table which I have created via SQL:
CREATE TABLE SAMPLETABLE (
[SAMPLECOLUMN] varchar(50)
)
GO
I then pull in the values for this sample column and others in my query which I have omitted for simplicity like so:
SELECT null as [SAMPLECOLUMN]
FROM TABLEX
I then try to update it...
update SAMPLETABLE
set
SAMPLETABLE.SAMPLECOLUMN = (SELECT CASE WHEN TABLEJ.COLUMNJ IN (...) THEN 'EXAMPLESTRING' END FROM TABLEJ)
from SAMPLETABLE
where SAMPLETABLE.SAMPLECOLUMN IS NULL
When I run this update in Visual Studio I get the error "Conversion failed when converting the varchar value 'EXAMPLESTRING' to data type int." The batch of statements used for the update runs perfectly fine in SSMS. It is clear that there is a conflict of data types according to the error, but I don't know why there should be. The 'EXAMPLESTRING' is clearly a string which is what I want and the data type of SAMPLECOLUMN is varchar(50).
I also get this same error if the value of column that I am using to update the null consists of strings.
What am I doing wrong here?
CREATE TABLE SAMPLETABLE (
[SAMPLECOLUMN] varchar(50)
)
GO
I then pull in the values for this sample column and others in my query which I have omitted for simplicity like so:
SELECT null as [SAMPLECOLUMN]
FROM TABLEX
I then try to update it...
update SAMPLETABLE
set
SAMPLETABLE.SAMPLECOLUMN = (SELECT CASE WHEN TABLEJ.COLUMNJ IN (...) THEN 'EXAMPLESTRING' END FROM TABLEJ)
from SAMPLETABLE
where SAMPLETABLE.SAMPLECOLUMN IS NULL
When I run this update in Visual Studio I get the error "Conversion failed when converting the varchar value 'EXAMPLESTRING' to data type int." The batch of statements used for the update runs perfectly fine in SSMS. It is clear that there is a conflict of data types according to the error, but I don't know why there should be. The 'EXAMPLESTRING' is clearly a string which is what I want and the data type of SAMPLECOLUMN is varchar(50).
I also get this same error if the value of column that I am using to update the null consists of strings.
What am I doing wrong here?