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 differenceCodePudding user response:
CHAR (11) type of no, because there is space, you'll seeone 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,