Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to compare the data of smallint with varchar

Posted on 2004-10-05
6
Medium Priority
?
339 Views
Last Modified: 2006-11-17
Hello, I have one field with type of smallint, and want to compared to another filed with type of varchar in differet table, both two fields have same meaning, now i want to compare them, how can i do a conversion, that say, Table A,field1: Line_nbr, varchar; Table B, field2:req_line_nbr. how can i do the comparsion of req_line_nbr with line_nbr? what function should i use? Thanks
0
Comment
Question by:shyline777
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
6 Comments
 
LVL 4

Expert Comment

by:strangelynormal1
ID: 12230665
SELECT *
FROM [Table A] a
         ,[Table B] b
WHERE CONVERT(VARCHAR(20),a.Line_nbr) = b.req_line_nbr
0
 

Author Comment

by:shyline777
ID: 12237988
i did the convert and only return 18 which should be 42, i found the problem coused by my extract function LEFT which Return TAB character clude, so can you tell me how can i extracted the characters before a TAB used as a delimiter in a data field?  Thank you so much
0
 
LVL 4

Accepted Solution

by:
strangelynormal1 earned 200 total points
ID: 12239724
Okay, let's assume that the field only has tab as a possible extra character.

SELECT *
FROM [Table A] a
         ,[Table B] b
WHERE a.Line_nbr = CONVERT(SMALLINT,REPLACE(b.req_line_nbr,CHAR(9),''))
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question