Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to use variable tablenames in SP
Message
 
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Stored procedures, Triggers, UDFs
Versions des environnements
SQL Server:
SQL Server 2008
Application:
Desktop
Divers
Thread ID:
01519190
Message ID:
01519226
Vues:
25
>>>In SQL Server you must use dynamic SQL for this purpose, e.g.
>>>
>>>declare @SQL nvarchar(max)
>>>
>>>set @SQL  = 'select * from ' + quotename(@TableName) + ' where UserName = @cUser'
>>>
>>>execute sp_ExecuteSQL @SQL, N'@cUser varchar(20)', @cUser
>>
>>Thanks, that looks really weird for a FoxPro guy, doesn't it? How did you ever get used to that?
>
>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)
Christian Isberner
Software Consultant
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform