Sample Header Ad - 728x90

use a table as a variable

-1 votes
1 answer
284 views
I was wondering if there was a way to set a table name in SQL to be a variable. I have a list of queries that hit the same table and didn't want to have to update them all so was hoping to declare the table name as a value. Below is an example: what I wanted to do is declare the table name once and use the @tablename in the queries shown below. /*at the field level */ SELECT ( SELECT COUNT(DISTINCT PROVIDER_TIN) AS PROVIDER_TIN from [Coloma].[dbo].Aetna_Medicare_2019 a WHERE PROVIDER_TIN = '' OR PROVIDER_TIN IS NULL ) AS NULL_TINS, ( SELECT COUNT(DISTINCT PROVIDER_ID) AS PROVIDER_ID from [Coloma].[dbo].Aetna_Medicare_2019 a WHERE PROVIDER_ID = '' OR PROVIDER_ID IS NULL ) AS NULL_IDS
Asked by Newelle Horn (21 rep)
Apr 11, 2019, 04:19 AM
Last activity: Apr 11, 2019, 05:23 AM