sql server - Cannot find the object 'TABLE" because it does not exist or you do not have permissions -


i running issue want add column table utilizes derived tables. want able populate column using while loop. however, when add column table following error: cannot find object "test" because not exist or not have permissions. have permissions not understanding why being prompted error when script executes without error without " alter table test add themevalue int(50)" line item added.

the following code:

declare @weekspriortoconversion int declare @periodenddate varchar(50)  set @weekspriortoconversion = 5 set @periodenddate = '2016-10-26'  select test.[casino]   (select c.casino                                       'casino',                tml.id                                         'id',                tml.[themes or game titles]                    'theme',                count(distinct sm.[serial number])             'title count',                sum(smd.[standardizedcasinoholdv2]) / sum(case                                                            when smd.[standardizedcasinoholdv2] <> 0                                                              7                                                            else null                                                          end) 'casino index'           [slot machine data] smd                inner join [slot machines] sm                  on sm .id = smd.[serial number]                inner join [slot machine configurations] smc                  on sm .id = smc.[serial number]                     , smc. [configuration starting date] = (select max([configuration starting date]) expr1                                                                 [slot machine configurations] smc2                                                                ( [serial number] = sm.id )                                                                      , ( [configuration starting date] <= smd.[data calendar start date] ))                inner join [casino] c                  on c .id = smc.[casino slot in operation]                inner join [themes master list] tml                  on tml.id = smc.[theme or game title]) test  alter table test   add themevalue int(50);  

there no int(50) datatype , can't add columns derived tables. derived tables encapsulate logical table expression in query. don't create kind of actual table.

likely want #temp table instead. can create 1 select ... into.

the below creates 1 called #test. select list includes themevalue column no need add separately.

select c.casino                                       [casino],        tml.id                                         [id],        tml.[themes or game titles]                    [theme],        count(distinct sm.[serial number])             [title count],        sum(smd.[standardizedcasinoholdv2]) / sum(case                                                    when smd.[standardizedcasinoholdv2] <> 0                                                      7                                                    else null                                                  end) [casino index],        cast(null int)                              themevalue   #test   [slot machine data] smd        inner join [slot machines] sm          on sm .id = smd.[serial number]        inner join [slot machine configurations] smc          on sm .id = smc.[serial number]             , smc. [configuration starting date] = (select max([configuration starting date]) expr1                                                         [slot machine configurations] smc2                                                        ( [serial number] = sm.id )                                                              , ( [configuration starting date] <= smd.[data calendar start date] ))        inner join [casino] c          on c .id = smc.[casino slot in operation]        inner join [themes master list] tml          on tml.id = smc.[theme or game title]  

Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -