Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to use variable tablenames in SP
Message
From
26/07/2011 12:50:57
 
General information
Forum:
Microsoft SQL Server
Category:
Stored procedures, Triggers, UDFs
Environment versions
SQL Server:
SQL Server 2008
Application:
Desktop
Miscellaneous
Thread ID:
01519190
Message ID:
01519229
Views:
22
>>>I spent some time in MSDN T-SQL forum and for me now writing VFP SQL query takes a bit of a time - writing SQL queries comes naturally.
>>
>>One other question, now that I have you on the line: Can I create a SP in SQL from VFP with SQLEXEC()?
>>
>>I tried something like this:
>>
>>
>>TEXT TO lcQuery TEXTMERGE NOSHOW
>>ALTER PROCEDURE [dbo].[UserHasAccess]
>>	@tnCoID int = 0, 
>>	@tcUsKey varchar(36) = ''
>>AS
>>BEGIN
>>	SET NOCOUNT ON;
>>	DECLARE @lcSQL nvarchar(max)
>>	SET @lcSQL  = 'select CAST(COUNT(*) AS int) AS FXCount from ' + 'Payroll' + ltrim(str(@tnCoId)) + '..Roles' + ' where DelFlag = 0 AND roUsKey = @tcUsKey'
>>	EXECUTE sp_ExecuteSQL @lcSQL, N'@tcUsKey varchar(36)', @tcUsKey
>>END TRANSACTION
>>ENDTEXT
>>
>>SQLEXEC(nConn,lcQuery)
>>
>
>Last line before ENDTEXT should be END (not END TRANSACTION).
>
>Are you getting an error once you fixed this error? I think it should work if you have sufficient rights with your connection to alter SP.

That is working now, thanks again.
Christian Isberner
Software Consultant
Previous
Reply
Map
View

Click here to load this message in the networking platform