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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:19:48+00:00 2026-06-18T10:19:48+00:00

So far I have this code: declare @random int, @upper int, @lower int, @rndtb

  • 0

So far I have this code:

declare @random int, @upper int, @lower int, @rndtb varchar(20)
set @lower = 1
set @upper = 999
select @random = ROUND(((@upper - @lower) * rand() + @lower),0)
select @rndtb = '##show'+cast(@random as varchar(20))+''

But that gives me

Conversion failed when converting the varchar value ‘##show’ to data type int.

What I am trying to achieve is to create a table ##show+random number each time the query is executed.

Example :

##show01
##show78
##show43

Edited with what @bluefeet said and found a way to create the table with

Declare @SQL VarChar(1000)

SELECT @SQL = 'Create Table ' + @rndtb + '('
SELECT @SQL = @SQL + 'ID int NOT NULL Primary Key, FieldName VarChar(10))'

Exec (@SQL)

but how do I call or insert into this table?

  • 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-18T10:19:50+00:00Added an answer on June 18, 2026 at 10:19 am

    Since you are adding the parameter @random to a string, you need to cast it as a varchar so it can be concatenated to the string portion:

    select @rndtb = '##show'+cast(@random as varchar(20))+''
    

    Your full code will be:

    declare @random int, @upper int, @lower int, @rndtb varchar(20)
    set @lower = 1
    set @upper = 999
    select @random = ROUND(((@upper - @lower) * rand() + @lower),0)
    select @rndtb = '##show'+cast(@random as varchar(20))+''
    

    Based on your edit, you will need to use dynamic sql to insert into the new table:

    select @SQL = 'insert into '+@rndtb+'
            select *
            from yourtable'
    
    
    exec (@sql)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code so far: DECLARE @AddressIDS TABLE ( AddressID int ) INSERT
Here is the code I have so far: DECLARE @bcpCommand varchar(2000) DECLARE @query varchar(2000)
I have this piece of code: BEGIN DECLARE @NewLine CHAR(2) SET @NewLine = CHAR(13)+CHAR(10)
I have this code so far which perfectly but relies on there being a
This is what I have as far as code, it is in the first
So far i have this: mov ah,02h mov cl,11001100001111011101000b ;6,692,584 in dec mov dl,0
Thanks to everyone out there helping newbies like me. So far I have this:
I have this so far but the Column 'name' is ambiguous, so I want
I have this so far but I don't know how to write over the
I have this so far: http://jsfiddle.net/u5vhS/54/ . What I want to be able to

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.