Click here to Skip to main content
15,884,889 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
my query is

SQL
delete from TestId where ID between 6 and 10


table contain id like
VB
08SANJAY3001
08SANJAY3002
08SANJAY3003



plz tell me how to solve it
Posted
Updated 17-Sep-14 23:37pm
v3
Comments
hypermellow 18-Sep-14 5:20am    
Can you post the table definition for TestID?
... maybe include some sample data??
sanjaysgh 18-Sep-14 5:23am    
id like
08SANJAY3001
08SANJAY3002
08SANJAY3003
hypermellow 18-Sep-14 5:31am    
So, if your ID column does not contain integer values ... why are you trying to delete rows with an ID value between 6 and 10?
What is it you trying to achieve?
George Jonsson 18-Sep-14 5:36am    
Eh, what is your expected result from such a conversion?
Is it the last digit you want?
[no name] 19-Sep-14 3:56am    
Buddy how can we compare string and integer? that error itself says a lot right?

Well... did you expect it to work?
When you do BETWEEN two integer values, SQL will assume that you want an integer comparison, not a strign comparison (and the sort order is different, so it's important). As a result, it tries to be helpful, and convert the column values to integer - and of course it fails, because there is non-numeric data in teh table. You can try converting your vlaues to string, but you will have to fill them with leading zeros:
SQL
DELETE FROM TestId WHERE id BETWEEN '06' AND '10'
 
Share this answer
 
The format of id value as given in your problem statement is incorrect.

Still assuming the first two characters as the number you would like to search in the between clause, you could do the following:

SQL
delete from TestId where  cast(substring('08Sanjay2011',1,2) as int) between 6 and 10

But this will not work if your between ranges more than 99 as the substring is derived only for first 2 characters.
 
Share this answer
 
Comments
sanjaysgh 18-Sep-14 6:35am    
It is not working
Try..


C#
TRY_CONVERT(int,'08SANJAY3001')
 
Share this answer
 
once you try with this..

DELETE FROM TestId WHERE id BETWEEN '08SANJAY3003' AND '08SANJAY3005'
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900