cheryl9063
asked on
TSQL Help2
I need a query that will pull all the rows where column2 has a number that ends in 09.. How?
For example if the number is 1309 I want it or 9909 etc..
For example if the number is 1309 I want it or 9909 etc..
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This will work in both condition if column is int or nvarchar
select * from TableName where <ColumnName> like '%09'
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This handles most data types and sizes without any problems
SELECT *
FROM MyTable
WHERE Cast(Column2 as varchar(max)) LIKE '%09'
If we know that the value is numeric, this can be changed to
SELECT *
FROM MyTable
WHERE Cast(Column2 as varchar(32)) LIKE '%09'
SELECT *
FROM MyTable
WHERE Cast(Column2 as varchar(max)) LIKE '%09'
If we know that the value is numeric, this can be changed to
SELECT *
FROM MyTable
WHERE Cast(Column2 as varchar(32)) LIKE '%09'
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
[Using % also requires that the column is an integer (of any size).]
but right(....,2) = "09" is a char-function
so an exctra convert(varchar...) is needed to be able to take the last 2 positions and compare it with "09"
select * from table where right(convert(varchar,conv