I have a view (Not created by me) :-
SELECT UPPER(SUBSTRING([Stock Code], PATINDEX('%[^0]%', [Stock Code]), LEN([Stock Code]))) AS StockCode, [Stock Code] AS StockCode2
FROM dbo.[tbl_My_Table]
WHERE ([Stock Code] = '02-1600HF')
It returns:
StockCode StockCode2 (I added this column)
2-1600HF 02-1600HF
This view feeds into a BI system and I don't want to break it, does anyone know what "PATINDEX('%[^0]%'" does and why it would be used?
I need to keep the leading Zeros 'StockCode' does not have them.
https://docs.microsoft.com/en-us/sql/t-sql/functions/patindex-transact-sql?view=sql-server-ver15
So in your case it points to the starting position of the first occurence of: ^0
Does that make sence?