Skip to content

Instantly share code, notes, and snippets.

@bertwagner
Last active September 1, 2017 21:34
Show Gist options
  • Save bertwagner/8b1acb4810f289aafe825d4aeb752304 to your computer and use it in GitHub Desktop.
Save bertwagner/8b1acb4810f289aafe825d4aeb752304 to your computer and use it in GitHub Desktop.
CREATE PROCEDURE dbo.sp_GetFullNameFromTable
@ParmTableName varchar(100),
@ParmUserName varchar(100)
AS
BEGIN
DECLARE @FullQuery nvarchar(1000)
SET @FullQuery = N'SELECT FullName FROM dbo.@TableName WHERE UserName = @UserName'
DECLARE @ParmDefinition nvarchar(100) = N'@TableName varchar(100), @UserName varchar(100)';
EXEC sp_executesql @FullQuery, @ParmDefinition,
@UserName = @ParmUserName,
@TableName = @ParmTableName;
END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment