Avatar of johnnyg123
johnnyg123Flag for United States of America

asked on 

Create temp table using dynamic sql

I have a stored procedure in which I need to create a single temp table based on one of several views

Each of the views has a differing amount of fields

I will use this table to turn around and  generate a csv file

Is there a way to put the view name into a variable and use that variable value to create the temp table?
Microsoft SQL ServerMicrosoft SQL Server 2008

Avatar of undefined
Last Comment
johnnyg123
SOLUTION
Avatar of zephyr_hex (Megan)
zephyr_hex (Megan)
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
SOLUTION
Avatar of Jim Horn
Jim Horn
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Wait.  Is the OP asking for a dynamic way to create a temp table based on 1 view ?   That's how I read it.  If that's not the case, then please disregard my earlier answer.
Avatar of Jim Horn
Jim Horn
Flag of United States of America image

Hmm .. looks like we'll need a clarification, as I interpreted it as multiple views, which after a second reading may not be correct.
ASKER CERTIFIED SOLUTION
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of johnnyg123
johnnyg123
Flag of United States of America image

ASKER

Thanks for all the posts!

After rereading my question I realized I was indeed unclear

I wanted to give at least some points to all posts

Ultimately scott's suggestion is the one I went with so I give him the most
Microsoft SQL Server
Microsoft SQL Server

Microsoft SQL Server is a suite of relational database management system (RDBMS) products providing multi-user database access functionality.SQL Server is available in multiple versions, typically identified by release year, and versions are subdivided into editions to distinguish between product functionality. Component services include integration (SSIS), reporting (SSRS), analysis (SSAS), data quality, master data, T-SQL and performance tuning.

171K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo