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 8902699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:40:45+00:00 2026-06-15T01:40:45+00:00

In SQL Server 2008 (TSQL), I’ve created a stored procedure like this: CREATE PROCEDURE

  • 0

In SQL Server 2008 (TSQL), I’ve created a stored procedure like this:

CREATE PROCEDURE SP_1_10_2
AS
declare @mostValuableBook nvarchar(255)
SELECT @mostValuableBook = Name
FROM books
WHERE price =
    ( SELECT MAX(price)
      FROM books
      WHERE izd LIKE '%BHV%' );
return @mostValuableBook
GO

But, when I’m trying to execute it:

declare @x nvarchar(255)
EXECUTE @x = SP_1_10_2;
SELECT 'The most expensive BHV book:', @x AS 'Name'
GO

I’m getting an error:

Conversion failed when converting the nvarchar value ‘Internet
Explorer 3 original’ to data type int.

It seems like the problem is in the line

EXECUTE @x = SP_1_10_2;

Can you please tell me what’s wrong? Why is it trying to convert to 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-15T01:40:47+00:00Added an answer on June 15, 2026 at 1:40 am

    RETURN cannot be used to return nvarchar / varchar such as you have. RETURN is used to return an integer, this can be expressed as some sort of status code 1=True / 0=False. Read more about return here: http://msdn.microsoft.com/en-us/library/ms174998.aspx

    In your case, you simply need to use OUTPUT variables which is similiar to pass-by-ref in C# or C++. You pass the variable to the sproc, the sproc modifies it, and you get the expected results after a SELECT....

    Change it so that your parameters becomes an output parameter:

    CREATE PROCEDURE SP_1_10_2
    @mostValueableBook nvarchar(255) output
    AS
    SELECT @mostValuableBook = Name
    FROM books
    WHERE price =
        ( SELECT MAX(price)
          FROM books
          WHERE izd LIKE '%BHV%' );
    SELECT @mostValuableBook
    GO
    

    Call it like so:

    DECLARE @theValBook nvarchar(255)
    EXECUTE SP_1_10_2 @mostValuableBook = @theValBook output
    

    Then you can say:

    SELECT 'Most expensive book is', @theValBook

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to create a sql stored procedure (Sql Server 2008 - T-SQL) which
I have following tsql code in sql server 2008: declare @ID INT SET @ID
I'm trying to create a simple trigger using TSQL (or SQL Server 2008). The
I have a T-SQL stored procedure in a SQL Server 2008 database that I
I have created a T-SQL query in SQL Server 2008 R2 that is a
I am using SQL Server 2008, and would like to be able to take
Using Entity Framework 4 with stored procedures and SQL Server 2008 SP1... When running
I'm writing tsql for SQL Server 2008. I've got two tables with roughly 2
I am using SQL Server 2008. I have 2 table variables like FirstName ==========
I have this scenario: WServer 2008, SQL Server 2005, MS Analysis services (SSAS), ISS7

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.