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

  • SEARCH
  • Home
  • 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 8463931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:35:14+00:00 2026-06-10T14:35:14+00:00

… Well, not exactly only for PRINT . I need to assign a string

  • 0

… Well, not exactly only for PRINT. I need to assign a string variable the value that mixes explicit substrings with integer values (and possibly with other type values). The goal is to get the string for logging.

So far, I use the code like:

DECLARE @msg nvarchar(1000)
...
SET @msg = @procname + 'result = ' + CAST(@result AS nvarchar(5))
                     + '; error = ' + CAST(@error AS nvarchar(5))

where the @procname is a string like sp_my_proc:, and the @result and the @error are integer variables. The result should look like (no extra spaces around the numbers, just the minimum length):

sp_my_proc: result = 3; error = 0

The above approach works, but… Is there any better way for converting an integer variable to the string than CAST(@result AS nvarchar(5))? (Consider the magic number 5 being a minor detail to be ignored.)

How do you solve the problem of generating such strings in your code?

Thanks, Petr

  • 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-10T14:35:16+00:00Added an answer on June 10, 2026 at 2:35 pm

    In SQL-Server you can use STR() function
    http://msdn.microsoft.com/ru-ru/library/ms189527.aspx
    The default value for ‘length’ parameter is 10. Since an integer variable is never longer than 10 symbols (you’d have an overflow) this will always work without errors:

    declare @test int
    set @test = 333333333
    select STR(@test)
    

    Also, take a look at
    String.Format like functionality in T-SQL?

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

Sidebar

Related Questions

so I did $subject = 'sakdlfjsalfdjslfad <a href=something/8230>lol is that true?</a> lalalala'; $subject =
English is not my native language. I need a software to spellcheck and correct
I have an element like this: <span class=tool_tip title=The full title>The ful&#8230;</span> This seems
(tl;dr: see summary at the bottom.) I am implementing an application that pulls content
I have this xml <entry id=1008 section=articles> <excerpt><p>&#8230; in Richtung „Aus für Tierversuche. Kosmetik-Fertigprodukte
Why does the Android system throw this Exception? 05-18 12:33:44.169 W/System.err( 8230): java.io.IOException: Is
I see that some rss on xml have strange strings. For example, ... is
CGI.escapeHTML is pretty bad, but CGI.unescapeHTML is completely borked. For example: require 'cgi' CGI.unescapeHTML('&#8230;')
I'm using a plugin to show only the first 500 characters of a text...
After much research, I have found that Laravel is very nice. I have a

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.