Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Invalid Column Name 2008 R2

Author  Topic 

jmpayaalvarez
Starting Member

1 Post

Posted - 2012-05-29 : 04:17:04
Hi all.

Mi first issue, mi first post. I hope this will be the first of many times that I can help or being helped.

This is what I got:

if ((select version from VersionInfo) = 11)
begin
select Tmp.HomeOperator,
Tmp.Operation,Tabla.CurrTechnology,
Tmp.Estado,Tiempo=sum(Tabla.Duration)
from #HSDPA Tmp,
(select t.sessionid,t.TestId,t.currtechnology,sum(t.Duration) as Duration
from #HSDPA h, technology t
where h.Operation in ('Downlink','Uplink')
and h.host not in ('10.132.144.18','194.224.26.150')
and h.testid=t.testid
group by t.sessionid,t.testid,t.currtechnology) as Tabla
where Tmp.testid=Tabla.Testid
and tabla.currtechnology is not null
group by Tmp.HomeOperator,Tmp.Operation,Tabla.CurrTechnology,Tmp.Estado ;
end
else
begin
select Tmp.HomeOperator,
Tmp.Operation,Tabla.CurrTechnology,
Tmp.Estado,Tiempo=sum(Tabla.Duration)
from #HSDPA Tmp,
(select a.sessionid,a.testid,a.currtechnology,sum(datediff(ms,a.msgtime,b.msgtime)) as Duration
from #HSDPA h, technology a,technology b
where h.Operation in ('Downlink','Uplink')
and h.host not in ('10.132.144.18','194.224.26.150')
and h.testid=a.testid
and a.testid=b.testid
and a.techid+1=b.techid
group by a.sessionid,a.testid,a.currtechnology) as Tabla
where Tmp.testid=Tabla.Testid
and tabla.currtechnology is not null
group by Tmp.HomeOperator,Tmp.Operation,Tabla.CurrTechnology,Tmp.Estado
end


As you may notice, the thing i want to do is simple. If the value of version is 11, then we launch some code, if not, we execute some different.

I'm programming this to execute on two different databases. Both of them have the technology table. Since this is not the problem, this table has not the same columns on both DB's. And SQL Server 2008 seems to pay attention to it, even if the code is not executed. I'm having the invalid column name on the red lighted below. It's true, techid isn't valid in the technology table i'm working with. I've noticed that piece of code is never reached adding an easy "PRINT 'Not Version 11';" line instead the other query and i don't have neither the invalid column error or the string printed on screen.

Is there any scripting option or something like that i can deactivated to avoid this problem? Is just like that Server 2008? I think this wouldn't be an issue using Server 2005, but this couldn't be the solution. I need some help on this, guys.

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2012-05-29 : 09:15:41
As a terribad cludge, you could do the ELSE part as dynamic SQL and execute it with sp_executesql.









How to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

For ultra basic questions, follow these links.
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2012-05-29 : 10:08:59
You could put the two pieces of code in SPs and execute them conditionally. They will create happily and only fail if called with missing objects.

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -