0

Can anyone help with this query?

SELECT        TOP (200) Material, Plant, StorLocation, Batch, 
LEFT(Batch, 1),
CASE WHEN LEFT(Batch, 1) <> '0' THEN 
    Batch  
ELSE 
    CONVERT(INT, Batch)
END AS BATCH, 

MaterialDescription, SLDays, Days, SLEDBBD, Unrestricted, BUn, Location, Status
FROM            ZMB5M
WHERE BATCH = '67918688Q0'

But it return an error :

Msg 245, Level 16, State 1, Line 2
Conversion failed when converting the nvarchar value '67918688Q0' to data type int.

Batch is in nvarchar, and i want to remove data in batch that have some '0' in start of data Thanks..

vie
  • 15
  • 6
  • 1
    '67918688Q0' 'Q' is clearly not a digit – Mitch Wheat Jan 30 '18 at 03:16
  • Your query and problem statement do not agree. Do you want to cast the column as an integer, or remove values which begin with a zero? – Tim Biegeleisen Jan 30 '18 at 03:19
  • My batch data is like this : 27835000, 0046417300, 391189, 70860L, 60841L, 4500276703, TAX17G1-01, A010H6B016, A010H7S005 – vie Jan 30 '18 at 03:20
  • yes @TimBiegeleisen , i want remove values which begin with a zero. Remove the '0' values – vie Jan 30 '18 at 03:21
  • Aggred with @MitchWheat '67918688Q0' is not a digit if you want to convert this get substring that would be '67918688' then you can convert this in int. – DHARMENDRA SINGH Jan 30 '18 at 03:24

0 Answers0