Re: Converting a field from int to varchar during query

From: Hugo Kornelis (hugo_at_pe_NO_rFact.in_SPAM_fo)
Date: 02/02/05


Date: Wed, 02 Feb 2005 23:58:27 +0100

On Wed, 2 Feb 2005 13:07:04 -0800, Jig Bhakta wrote:

>I have a query where I am writing the following statement:
>
>select * from ......
>where table1.field1 = table2.field2
>....
>....
>....
>
>field2 is a varchar field and field1 is an int field. Field2 contains the
>data mapping data for field1 and also other unrelated data as character
>strings.
>
>How do I run this query without getting the error - "Syntax error converting
>the varchar value 'XXXX' to a column of data type int."

Hi Jignesh,

Try:

select * from ......
where CAST(table1.field1 AS varchar(10)) = table2.field2
....
....
....

Best, Hugo

-- 
(Remove _NO_ and _SPAM_ to get my e-mail address)


Relevant Pages

  • Re: Conversion error
    ... You canimport both types of data into a varchar column now. ... Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP) ... www.SQLDTS.com - The site for all your DTS needs. ... >>character data has to be one or the other. ...
    (microsoft.public.sqlserver.dts)
  • Re: Char and Varchar
    ... >>If changing an element to full size causes it to no longer fit on the ... > forwarding pointer is changed. ... >>Would you ever create a table with lets say 100 single character VARCHAR ...
    (microsoft.public.sqlserver.server)
  • Re: Char and Varchar
    ... >>If changing an element to full size causes it to no longer fit on the ... > forwarding pointer is changed. ... >>Would you ever create a table with lets say 100 single character VARCHAR ...
    (microsoft.public.sqlserver.programming)
  • Re: trying to write my 1st stored procedure
    ... non-Unicode character data with a length of n bytes. ... for varchar are char varying or character varying. ... @bugtext nvarchar, @idkey int OUTPUT ... it is a new bug and return -1, ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: varchar problem
    ... A space is just another character. ... >> want to strip them, ... VARCHAR strings will only be as long as ... > the stored string itself. ...
    (alt.php)