Home > database >  A SQL get Numbers and contrast
A SQL get Numbers and contrast

Time:10-06

Example data for: sh201911 wx201910 shx201908 keid201911 monthly result format, this is letter is textual field properties, I'm going to take years, and then compared with other do,

RIGHT (TD002, 6) + 0 & lt; 201911

But in the end did not search to less than 201911 data, the data to determine the existence, whether the text can't compare, or where there is a problem? Specific command is as follows:

Select * from dbo. COPTD WHERE RIGHT (TD002, 6) + 0 & lt; 201911 and TD016='N'

CodePudding user response:

Use nvarchar tested the should be and TD002 what specific field type?
The test data
 -If not object_id (N 'Tempdb for.. # T ') is null 
Drop table # T
Go
The Create table # T ([TD002] nvarchar (30))
Insert # T
Select N 'sh201911' union all
Select N 'wx201910' union all
Select N 'shx201908' union all
Select N 'keid201911'
Go
- the end of the test data
Select * from # T WHERE RIGHT (TD002, 6) & lt; 201911


CodePudding user response:

TD002 is textual,

CodePudding user response:

CodePudding user response:

Also ask next, comparing data, I in 201911 and in '201911' is there a difference

CodePudding user response:

CHAR (11) type of no, because there is space, you'll see
one output
 Select RIGHT (TD002, 6), * from # T WHERE RIGHT (TD002, 6) & lt; 201911 



To try this
 Select RIGHT (REPLACE (TD002, ' ', '), 6), * from # T WHERE RIGHT (REPLACE (TD002, ' ', '), 6) & lt; 201911 

CodePudding user response:

Understand, thank you,
  • Related