Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8908973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:19:13+00:00 2026-06-15T03:19:13+00:00

I have this query: DECLARE @selectsql nvarchar(4000), DECLARE @cnt int select @selectsql = ‘

  • 0

I have this query:

DECLARE @selectsql nvarchar(4000),
DECLARE @cnt int

select @selectsql = ' SELECT ' + @cnt + '= COUNT(*) FROM Vwbckup' 

print @selectsql
print @cnt

EXEC sp_executesql @selectsql

When I execute the query I’m getting this error:

Conversion failed when converting the varchar value ‘ SELECT ‘ to data type int.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T03:19:14+00:00Added an answer on June 15, 2026 at 3:19 am

    You don’t apparently need dynamic SQL for this but in case you do for some reason not shown you don’t need to concatenate that part at all. You can use an OUTPUT parameter.

    DECLARE @selectsql NVARCHAR(4000),
            @cnt       INT
    
    SELECT @selectsql = N'SELECT @cnt = COUNT(*) FROM Vwbckup'
    
    PRINT @selectsql
    
    PRINT @cnt
    
    EXEC sp_executesql
      @selectsql,
      N'@cnt int output',
      @cnt OUTPUT
    
    SELECT @cnt 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have this query: SELECT HOUR( DATE ) AS hr, COUNT( * ) AS cnt
I have query like this DECLARE @A INT SET @A = 22 SELECT Moo,
Let's say I have this SQL query: declare @input varchar(20) select * from myTable
I have built a T-SQL query like this: DECLARE @search nvarchar(1000) = 'FORMSOF(INFLECTIONAL,hills) AND
I have this query... SELECT Distinct([TargetAttributeID]) FROM (SELECT distinct att1.intAttributeID as [TargetAttributeID] FROM AST_tblAttributes
i have this query: SELECT `completed`.`ID` AS `ID`,`completed`.`level` AS `level`,`completed`.`completed_in` AS `completed_in`, COUNT(1) AS
I have a query that works: DECLARE @ProductID int SET @ProductID = '1234' SELECT
I have this query DECLARE @Test TABLE ( RowID INT IDENTITY(1,1) PRIMARY KEY ,[Name]VARCHAR(10)
I have problem with this query DECLARE @INPUT INT SET @INPUT = 12345 ;
I have this SQL Server query: DECLARE @HoursUsed float SELECT COLUMN_A ,(SELECT (@HoursUsed =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.