Έχω την παρακάτω function σε Access και θέλω να την μετατρέψω για τον SQL 2005. Είναι η πρώτη function που φτιάχνω για τον SQL και αντιμετωπίζω κάποια δυσκολία.
Function ClearLeadingZero(xString)
ClearLeadingZero = ""
If Not (IsNull(xString) Or IsEmpty(xString) Or xString = "") Then
Static tempString, j, curDigit
j = 1
curDigit = Mid(xString, j, 1)
Do Until (curDigit <> "0" Or j > Len(xString))
j = j + 1
curDigit = Mid(xString, j, 1)
Loop
If j <= Len(xString) Then
ClearLeadingZero = Trim(Mid(xString, j, Len(xString) - j + 1))
End If
End If
End Function
Όταν πάω να την κάνω save μου χτυπάει στα 2 παρακάτω σημεία.
An expression of non-boolean type specified in a context where a condition is expected, near 'Or'.
Incorrect syntax near the keyword 'if'
Trim is not a recognised built-in function name'
Αντι για την Trim ποιά θα μπορούσα να χρησιμοποιήσω... και τι λάθος έχει η IF..
ALTER PROCEDURE [dbo].[ClearLeadingZero]
(@xString varchar(60))
AS
declare @return varchar(25)
If Not (IsNull(@xString,0) Or IsEmpty(@xString) Or @xString = '')
declare @tempString varchar(50)
declare @J int
declare @curDigit int
select @j = 1
select @curDigit = substring(@xString, j, 1)
While (@curDigit <> "0" Or @j > Len(@xString))
select @j = j + 1
select @curDigit = substring(@xString, j, 1)
End
If @j <= Len(@xString)
select @return = Trim(substring(xString, j, Len(xString) - j + 1))
Dionisis