Menu
  • HOME
  • TAGS

Table expression and table variable/temporary table persistence

sql-server,persistence,common-table-expression,temp-tables,table-variable

Speaking from my experience Imagine you insert 10 million records into temp table and use it for only one time. It will be sheer waste of time, memory and cpu. To use huge temp table more efficiently you also need to create index on top of the temp table. While,...

Replace column text from a list of reserved words

sql-server,tsql,replace,user-defined-functions,table-variable

First, simplify your question to just focus on the company name. The join back to product is trivial, but it complicates the query unnecessarily. Your basic query is: select replace(c.Company_Name, f.findword,'') as NewCompanyName, f.findWord, sep.col FROM COMPANY c CROSS APPLY dbo.SeparateValues(c.company_name, ' ') sep LEFT OUTER JOIN @findreservedwords f on...

Dynamic SQL with varchar in replace of table variable

sql-server,dynamic-sql,table-variable

Try set @sql = 'select * from ' + @Table execute SP_EXECUTESQL @sql I should also mention that you can include the parameter in your sp_executesql call DECLARE @Month VARCHAR(6) DECLARE @Table VARCHAR(32) DECLARE @sql NVARCHAR(MAX) DECLARE @MonthCount INT DECLARE @ParmDefinition NVARCHAR(500); WHILE @MonthCount > 0 BEGIN SELECT @Month =...