Store the value of a query into a SQL Server variable
问题 The objective of the code is to run a query dynamically and return 0 if there are no rows with data present in the columns and to return 1 if there are rows with data in the columns. This is my code for the stored procedure: ALTER proc [dbo].[usp_ColumnFieldValidator] ( @TblName nvarchar(30), @ColumnName nvarchar(30), @RetVal bit output ) as begin declare @CountOfRowsQuery as nvarchar(300) set @CountOfRowsQuery = 'select count('+quotename(@ColumnName)+') from '+quotename(@TblName)+' having