Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Call SQL UDF
Message
From
28/06/2010 10:49:25
 
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
Miscellaneous
Thread ID:
01470700
Message ID:
01470793
Views:
41
Thank you


>>Hi All,
>>I have a problem when calling SQL server scalar function from VFP9.
>>If I use the following syntax :
>>
>>
>>lcReturnValue='     '
>>lcParametersIn=['A','B','C']
>>lcComamnd=[EXEC ?@lcReturnValue=dbo.MyFunctionMane ]+lcParametersIn
>>lRet=SQLEXEC(nHandle,lcCommand)
>>
>>
>>I expect lRet=1 and lcReturnValue=whatever my function returns
>>This works on my machine when I run against SQL server 2005 and 2008 back end, but on my laptop and my coworkers computers it fails, with "...syntax error around '=' "
>>
>>The following will work on any machine.
>>
>>
>>lcComamnd=[SELECT dbo.MyFunctionMane(]+lcParametersIn+[)]
>>lRet=SQLEXEC(nHandle,lcCommand)
>>SELECT SqlResult
>>
>>
>>For testing purposes I created a simple function that imitates PADL() in VFP.
>>In SQL Server
>>
>>
>>IF OBJECT_ID(N'dbo.PADL', N'FN') IS NOT NULL
>>    DROP FUNCTION dbo.PADL;
>>GO
>>CREATE Function [dbo].[PADL] (@_String nvarchar(255),@_Len int=10,@_PadChar char(1)='0')
>>        Returns nvarchar(255)
>>        BEGIN
>>			SET @_String=REPLICATE(@_PadChar, case when @_Len>=len(LTRIM(RTRIM(@_String))) then @_Len-len(LTRIM(RTRIM(@_String))) else 0 end ) + LTRIM(RTRIM(@_String))
>>		    RETURN @_String
>>        END 
>>
>>
>>IN VFP I make a call to this function
>>
>>
>>pcReturn=' '
>>lcCommand=[EXEC ?@pcReturn=dbo.PADL '123',10,'0']
>>lnreturn=SQLEXEC(nHandle,lcCommand)   && on my computer return 1, on my laptop returns -1
>>?pcReturn   && on my computer returns '0000000123'
>>
>>lcCommand=[SELECT dbo.Padl('123',10,'0')]
>>lnreturn=SQLEXEC(nHandle,lcCommand)
>>SELECT SqlResult
>>BROWSE      && works on both computers
>>
>>
>>Is there some kind of settings on the server that I am missing.
>>Any suggestions please.
>>
>>Thank you in advance
>>
>>Yelena
>
>IMHO, only select syntax should work. Or you should declare the variable first, say,
>
>declare pcReturn varchar(100)
>
>pcReturn = dbo.myFunc(params)
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform