SQL Bugging me

mole999

Well-known Member
Joined
Oct 23, 2004
Messages
10,524
Office Version
  1. 2019
  2. 2016
  3. 2013
Platform
  1. Windows
This works
case when (isnumeric(SUBSTRING(DRL.LICENCE_NUMBER,7,2))) = 1 AND SUBSTRING(DRL.LICENCE_NUMBER,7,2) >12 then 'X' else SUBSTRING(DRL.LICENCE_NUMBER,7,2) end,

I want to change 'X' to

SUBSTRING(DRL.LICENCE_NUMBER,7,2) -50,

it throws an error as some of the values retrieved aren't numeric so tried

isnumeric(SUBSTRING(DRL.LICENCE_NUMBER,7,2))) = 1 AND SUBSTRING(convert(varchar(2),DRL.LICENCE_NUMBER),7,2)-50
or
isnumeric(SUBSTRING(DRL.LICENCE_NUMBER,7,2)) = 1 AND SUBSTRING(DRL.LICENCE_NUMBER),7,2)-50

it could BE IF something something, but I'm not seeing it, any thoughts
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Did you try nesting it?

I am guessing it doesn't like you checking to see if it is numeric and then doing a number comparison in the same statement, because if it is not numeric, I think it might still be testing the number comparison, which will bomb out.
Maybe something like the first reply here: sql - Check if field is numeric, then execute comparison on only those field in one statement? - Stack Overflow
or the structure of the nested Case statement shown here: IsNumeric, IsInt, IsNumber - Microsoft SQL Server: Programming FAQ - Tek-Tips
 
Upvote 0
Thanks, i'll go do some checking
 
Upvote 0
well I can't use it in the WHERE clause (testing 3000 plus) and need to have a physical value as a compare, and I can't add functions to the environment hohum
 
Upvote 0
changed it slightly, didn't actually need to remove 50 just make it recognisable,

SUBSTRING(DRL.LICENCE_NUMBER,9,2)+'/'+case when isnumeric(SUBSTRING(DRL.LICENCE_NUMBER,7,1)) = 1 then replace(REPLACE(SUBSTRING(DRL.LICENCE_NUMBER,7,1),'5','0') ,'6','1') else SUBSTRING(DRL.LICENCE_NUMBER,7,1) end +''+SUBSTRING(DRL.LICENCE_NUMBER,8,1)+'/'+SUBSTRING(DRL.LICENCE_NUMBER,6,1)+''+SUBSTRING(DRL.LICENCE_NUMBER,11,1) As [DL DOBtest],
 
Upvote 0

Forum statistics

Threads
1,225,763
Messages
6,186,897
Members
453,384
Latest member
BigShanny

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top