Friday, March 9, 2012

invalid column name

When I try to run this script I get the 'invalid column name error. Can
anyone tell me what I need to do to correct the error?
SELECT PROVIDER.PROV_PATH,
INSAGRE.PROV_ID,
PROVIDER.NAME,
INSEMPL.EMP_MO,
INSEMPL.EMP_YR,
INSEMPL.EMP_CNT,
CAST(cast([EMP_MO] as varchar) + '/1/' + CAST([EMP_YR] as varchar)
as datetime) AS MonthYear
INTO #Temp
FROM INSEMPL
INNER JOIN INSAGRE ON INSEMPL.INSAGRE_ID = INSAGRE.INSAGRE_ID
INNER JOIN PROVIDER ON INSAGRE.PROV_ID = PROVIDER.PROV_ID
WHERE (PROVIDER.PROV_PATH = 4)
-- Get Last Update Date
SELECT Max(MonthYear) as MaxMonthYear, INSAGRE_ID
INTO #Temp1
FROM #Temp
Group by INSAGRE_ID
-- Select Info from Last Update Date
SELECT t.*
FROM #Temp t INNER JOIN #Temp1 t1 ON t1.Prov_ID = t.Prov_ID AND
t1.MaxMonthYear = t.MonthYear
-- Clean Up
DROP TABLE #Temp
DROP TABLE #Temp1
Message posted via http://www.droptable.comI think it's an invalid error message. The problem is that you are
running them all together as one batch. and the #Temp doesn't exist, so the
select's from #temp burp.. See if adding a go in between helps, or try
running them one at a time..
Bill
"Jay via droptable.com" <forum@.droptable.com> wrote in message
news:136dcaa2482a4c0b8e96f1235bd182b8@.SQ
droptable.com...
> When I try to run this script I get the 'invalid column name error. Can
> anyone tell me what I need to do to correct the error?
> SELECT PROVIDER.PROV_PATH,
> INSAGRE.PROV_ID,
> PROVIDER.NAME,
> INSEMPL.EMP_MO,
> INSEMPL.EMP_YR,
> INSEMPL.EMP_CNT,
> CAST(cast([EMP_MO] as varchar) + '/1/' + CAST([EMP_YR] as v
archar)
> as datetime) AS MonthYear
> INTO #Temp
> FROM INSEMPL
> INNER JOIN INSAGRE ON INSEMPL.INSAGRE_ID = INSAGRE.INSAGRE_ID
> INNER JOIN PROVIDER ON INSAGRE.PROV_ID = PROVIDER.PROV_ID
> WHERE (PROVIDER.PROV_PATH = 4)
>
> -- Get Last Update Date
> SELECT Max(MonthYear) as MaxMonthYear, INSAGRE_ID
> INTO #Temp1
> FROM #Temp
> Group by INSAGRE_ID
>
> -- Select Info from Last Update Date
> SELECT t.*
> FROM #Temp t INNER JOIN #Temp1 t1 ON t1.Prov_ID = t.Prov_ID AND
> t1.MaxMonthYear = t.MonthYear
> -- Clean Up
> DROP TABLE #Temp
> DROP TABLE #Temp1
> --
> Message posted via http://www.droptable.com|||It looks like #Temp doesn't have an INSAGER_ID column, so the statement:
SELECT Max(MonthYear) as MaxMonthYear, INSAGRE_ID
INTO #Temp1
FROM #Temp
Group by INSAGRE_ID
Is probably generating the error. Try adding an INSAGRE_ID column to the
SELECT ... INTO #Temp statement.
"Jay via droptable.com" <forum@.droptable.com> wrote in message
news:136dcaa2482a4c0b8e96f1235bd182b8@.SQ
droptable.com...
> When I try to run this script I get the 'invalid column name error. Can
> anyone tell me what I need to do to correct the error?
> SELECT PROVIDER.PROV_PATH,
> INSAGRE.PROV_ID,
> PROVIDER.NAME,
> INSEMPL.EMP_MO,
> INSEMPL.EMP_YR,
> INSEMPL.EMP_CNT,
> CAST(cast([EMP_MO] as varchar) + '/1/' + CAST([EMP_YR] as v
archar)
> as datetime) AS MonthYear
> INTO #Temp
> FROM INSEMPL
> INNER JOIN INSAGRE ON INSEMPL.INSAGRE_ID = INSAGRE.INSAGRE_ID
> INNER JOIN PROVIDER ON INSAGRE.PROV_ID = PROVIDER.PROV_ID
> WHERE (PROVIDER.PROV_PATH = 4)
>
> -- Get Last Update Date
> SELECT Max(MonthYear) as MaxMonthYear, INSAGRE_ID
> INTO #Temp1
> FROM #Temp
> Group by INSAGRE_ID
>
> -- Select Info from Last Update Date
> SELECT t.*
> FROM #Temp t INNER JOIN #Temp1 t1 ON t1.Prov_ID = t.Prov_ID AND
> t1.MaxMonthYear = t.MonthYear
> -- Clean Up
> DROP TABLE #Temp
> DROP TABLE #Temp1
> --
> Message posted via http://www.droptable.com|||I am getting this error when trying to open up a new diagram through SQL
Enterprise Manager. Anyone got a solution for this? Invalid Column Name
'value'
"Jay via droptable.com" wrote:

> When I try to run this script I get the 'invalid column name error. Can
> anyone tell me what I need to do to correct the error?
> SELECT PROVIDER.PROV_PATH,
> INSAGRE.PROV_ID,
> PROVIDER.NAME,
> INSEMPL.EMP_MO,
> INSEMPL.EMP_YR,
> INSEMPL.EMP_CNT,
> CAST(cast([EMP_MO] as varchar) + '/1/' + CAST([EMP_YR] as
varchar)
> as datetime) AS MonthYear
> INTO #Temp
> FROM INSEMPL
> INNER JOIN INSAGRE ON INSEMPL.INSAGRE_ID = INSAGRE.INSAGRE_ID
> INNER JOIN PROVIDER ON INSAGRE.PROV_ID = PROVIDER.PROV_ID
> WHERE (PROVIDER.PROV_PATH = 4)
>
> -- Get Last Update Date
> SELECT Max(MonthYear) as MaxMonthYear, INSAGRE_ID
> INTO #Temp1
> FROM #Temp
> Group by INSAGRE_ID
>
> -- Select Info from Last Update Date
> SELECT t.*
> FROM #Temp t INNER JOIN #Temp1 t1 ON t1.Prov_ID = t.Prov_ID AND
> t1.MaxMonthYear = t.MonthYear
> -- Clean Up
> DROP TABLE #Temp
> DROP TABLE #Temp1
> --
> Message posted via http://www.droptable.com
>

No comments:

Post a Comment