Share via


How to Compare two nvarchar datatype values?

Question

Wednesday, December 1, 2010 5:58 AM

Hi All,

This is sriram.I need help from you.In one of my stored procedure I have to compare two nvarchar datatype values.The values containing both numerical and characters.Which function should I write? And one more problem i.e if a number containing zeros in starting ,I should also match including zeros.But not omit zeros.

Regards,

N.SRIRAM

All replies (2)

Thursday, December 2, 2010 1:45 AM âś…Answered | 1 vote

In Transact-SQL you use the standard comparison operators (such as =, <, >) to compare strings like NVARCHARs: http://msdn.microsoft.com/en-us/library/ms189863.aspx. Something like:

WHERE Column1 = Column2

or

WHERE Column1 = N'MyUnicodeString'

If you need to remove leading or trailing characters, you might have to use functions such as RTRIM or LTRIM: http://msdn.microsoft.com/en-us/library/ms181984.aspx.

If you need more help, please give an example of the string values you are trying to compare, or a sample of the code you currently have.

Alan Brewer [MSFT] SQL Server Documentation Team This posting is provided "AS IS" with no warranties, and confers no rights.


Wednesday, December 25, 2019 9:45 PM

I have requirement  compare nvarchar(50) column with numeric(18,0), Please suggest how to compare

Example:

TABLE 1, COLUMN ITEMNUMBER (NVARCHAR(50)) WITH POSSIBLE VALUES (NO SUB, NULL, 232232)

TABLE 2, Column item (Number(18,0)) with possible values of only numbers

now i need to compare both columns by join

i tried casting, but getting error for value 'NO SUB'.

Please help