Avatar of RUA Volunteer2?
RUA Volunteer2?Flag for United States of America

asked on 

How do I create a temporary table that will omit specific values

I think the format is something like this:
if object_id('tempdb..#special_types') is not null drop table #special_types
      create table #special_types
      (
        special_type_code varchar(100) collate database_default
      )
      insert into #special_types select value from dbo.c_split(@special_type_code,',')

The Special Codes that need to be omitted are. Where would this go.
" tbl.special_code not in ('192','703','A95','705','A955','7054') "

I am assuming this table would then need to be joined in the FROM statement to pull those records back in. 
Microsoft SQL Server

Avatar of undefined
Last Comment
Scott Pletcher
ASKER CERTIFIED SOLUTION
Avatar of David Todd
David Todd
Flag of New Zealand 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
Avatar of RUA Volunteer2?

ASKER

I thought it would have been something like this since the format below seems to be the way other developers I work with expect it. I have a long series of these temp tables " if object_id('tempdb..# none of them omit values.

if object_id('tempdb..#special_types') is not null
AND tbl.special_code not in ('192','703','A95','705','A955','7054') 
drop table #special_types create table #special_types
      (
        special_type_code varchar(100) collate database_default
      )
      insert into #special_types select value from dbo.c_split(@special_type_code,',')
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.
It works quicker than #tmp because TABLE-VARIABLE located in-memory and does not require disk I/O.

False.  There is no difference between #table and @table as far as memory / disk usage goes.  @table can go to disk just like #table can.

If you think about it, this must be true.  What if you put a 200M rows into an @table?  Would SQL allow itself to crash because it tried to force it all into RAM?  Of course not.  It would spool it out to disk, just like it does with #tables.
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