Solved

How to compare the data of smallint with varchar

Posted on 2004-10-05
6
329 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
  • 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 50 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Server encoding for storing Indian languages 9 37
Using Aggregate Functions to Count 3 34
datetime in sql 6 31
MS SQL Pivot table help 4 14
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
I have a large data set and a SSIS package. How can I load this file in multi threading?
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

896 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now