create a quick temp table with stored procedure sql

/* First you need to create a table type. */
CREATE TYPE Names AS TABLE 
(Name VARCHAR(10)) ;
GO
 
/* Next, Create a procedure to receive data for the table-valued parameter, the table of names and select one item from the table*/
CREATE PROCEDURE ChooseAName
  @CandidateNames Names READONLY
AS 
DECLARE @candidates TABLE (NAME VARCHAR(10),
                           theOrder UNIQUEIDENTIFIER)
INSERT  INTO @candidates (name, theorder)
        SELECT  name, NEWID()
        FROM    @CandidateNames
SELECT TOP 1
        NAME
FROM    @Candidates
ORDER BY theOrder
GO
 
/* Declare a variable that references the type for our list of cows. */
DECLARE @MyFavouriteCowName AS Names ;
 
/* Add data to the table variable. */
INSERT  INTO @MyFavouriteCowName (Name)
 SELECT 'Bossy' UNION SELECT 'Bessy' UNION SELECT 'petal' UNION SELECT 'Daisy' UNION SELECT 'Lulu' UNION SELECT 'Buttercup' UNION SELECT 'Bertha' UNION SELECT 'Bubba' UNION SELECT 'Beauregard' UNION SELECT 'Brunhilde' UNION SELECT 'Lore' UNION SELECT 'Lotte' UNION SELECT 'Rosa' UNION SELECT 'Thilde' UNION SELECT 'Lisa' UNION SELECT 'Peppo' UNION SELECT 'Maxi' UNION SELECT 'Moriz' UNION SELECT 'Marla'
 
/* Pass the table with the list of traditional nemes of cows to the stored procedure. */
EXEC chooseAName @MyFavouriteCowName
GO

4
4
Awgiedawgie 440220 points

                                    SET nocount ON
 
DECLARE @FirstTable TABLE (RandomInteger INT)
DECLARE @SecondTable TABLE (RandomInteger INT)
DECLARE @WhenWeStarted DATETIME
DECLARE @ii INT
 
BEGIN TRANSACTION
SET @ii = 0
WHILE @ii < 100000 
  BEGIN
    INSERT  INTO @FirstTable
    VALUES  (RAND() * 10000)
    SET @ii = @ii + 1
  END
SET @ii = 0
WHILE @ii < 100000 
  BEGIN
    INSERT  INTO @SecondTable
    VALUES  (RAND() * 10000)
    SET @ii = @ii + 1
  END
COMMIT TRANSACTION
SELECT  @WhenWeStarted = GETDATE()
SET STATISTICS PROFILE ON
SELECT  COUNT(*)
FROM    @FirstTable first
        INNER JOIN @SecondTable second 
        ON first.RandomInteger = second.RandomInteger OPTION (RECOMPILE)
  -- 153Ms  as opposed to 653Ms without the hint
SET STATISTICS PROFILE OFF
SELECT  'That took ' 
    + CONVERT(VARCHAR(8), DATEDIFF(ms, @WhenWeStarted, GETDATE())) 
    + ' ms'
go

4 (4 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
sql create and execute temp stored procedure sql stored procedure results into temp table sql stored procedure result into temp table how to insert into temp table from stored procedure in sql server SQL execute stored procedure to temp table temp table sql server stored procedure t-sql use temp table in stored procedure how to select a stored procedure into a temp table sql create temp stored procedure temp table in stored procedure sql server create temp table and insert data from stored procedure temp table in stored procedure sql server example stored procedure into temp table stored procedure create temp table sql procedure create temp table how to create a temp table for stored procedure parameter using sql server mysql create temp table from stored procedure create temp table from stored procedure create a temp table from an exec stored procedure sql stored procedure select into temp table create temp table in sql server stored procedure sql server store procedure into temp table sql server stored procedure into temp table sql stored procedure into temp table mysql create temp table in stored procedure create stored procedure with temp table sql server select into temp table in stored procedure sql serveer Can we get result from temporary table sql server stored procedure temp table stored procedure sql temp table can you use an existing temporary table from another procedure tsql temp table name numeric allowed tsql temp table numeric allowed tempoary table sql stored procedure declare temporali table create temp table on bases of the exec stored procedure create tem table sql stored procedure sql stored procedure create virtual table ms sql stored procedure with temporary table create temp table sql in proc sql temp table stored procedure temp table in sql stored procedure Execute the stored procedure created in question 4.1, and add 2 rows of data in the ShoppingCart table Execute the stored procedure created in question 4.1, and add 2 rows of data in the ShoppingCart table. stored procedure sql server temp table temptable store procedure creating a temp table in sql server stored procedure and select into it stored procedure temp table sql how to create temp table in sql for job How can you Create a table in sql using data from a temp tables how to use temp table from different stored procedure sql server create a temp table in sql without printing
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source