SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


'Invalid Column Name' Error


'Invalid Column Name' Error

Author
Message
dcwhitson
dcwhitson
SSC Rookie
SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)

Group: General Forum Members
Points: 29 Visits: 3
I've looked for the last two days trying to figure this out and no other solutions or posts seem to work or apply to my problem.

I have recreated this SQL Express database three times. The first time, I scripted it from another database, and the last two times, I started from scratch and still get the same error.

I am using this query:

SELECT
dbo.shops.bizID,
dbo.shops.bizName,
dbo.shops.bizPhone,
dbo.shops.bizURL,
dbo.shops.bizLogo
FROM
dbo.bizInCat
INNER JOIN dbo.Category ON (dbo.bizInCat.catID = dbo.Category.catID)
INNER JOIN dbo.shops ON (dbo.bizInCat.bizID = dbo.shops.bizID)
WHERE
dbo.shops.bizState = @state AND
dbo.shops.bizCity = @city AND
dbo.shops.bizActive = 'True' AND
dbo.Category.catName = @category

I KNOW that the columns bizState and bizCity exist. If I run the query in SSMS either on my local machine, or on the server, it works. It also worked when I plugged it into MS SQL Code Factory. But it will not work when ran in visual web developer, or running the application in the production environment. I always get the Invalid Column Name error for bizState and bizCity. If I remove those two constraints from the where clause, it works in both web developer and live on the production server.

Can anyone explain to me what is going on with these two columns? I've tried Ctrl+Shift+R, rebooting the server, recreating the DataSet in developer and nothing seems to work. This is driving me nuts! It's a pretty simple app and database query!

Thanks in advance...
GilaMonster
GilaMonster
SSC Guru
SSC Guru (224K reputation)SSC Guru (224K reputation)SSC Guru (224K reputation)SSC Guru (224K reputation)SSC Guru (224K reputation)SSC Guru (224K reputation)SSC Guru (224K reputation)SSC Guru (224K reputation)

Group: General Forum Members
Points: 224667 Visits: 46320
Can you post the CREATE TABLE statement for the Shops table please?

Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


dcwhitson
dcwhitson
SSC Rookie
SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)

Group: General Forum Members
Points: 29 Visits: 3
I used the auto generated one from SSMS

USE [DB_CW01_SiHu]
GO

/****** Object: Table [dbo].[shops] Script Date: 01/12/2012 13:00:19 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[shops](
[bizID] [int] IDENTITY(1,1) NOT NULL,
[bizName] [nvarchar](255) NULL,
[bizPhone] [nvarchar](15) NULL,
[bizURL] [nvarchar](500) NULL,
[bizLogo] [nvarchar](max) NULL,
[clicks] [int] NULL,
[clickReset] [datetime] NULL,
[clickTotal] [int] NULL,
[bizActive] [bit] NOT NULL,
[bizCreated] [datetime] NULL,
[bizRate] [decimal](18, 0) NULL,
[lastPayment] [datetime] NULL,
[userID] [uniqueidentifier] NULL,
[contactName] [nvarchar](250) NULL,
[contactEmail] [nvarchar](250) NULL,
CONSTRAINT [PK_shops] PRIMARY KEY CLUSTERED
(
[bizID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

ALTER TABLE [dbo].[shops] ADD CONSTRAINT [DF_shops_bizActive] DEFAULT ('False') FOR [bizActive]
GO
GilaMonster
GilaMonster
SSC Guru
SSC Guru (224K reputation)SSC Guru (224K reputation)SSC Guru (224K reputation)SSC Guru (224K reputation)SSC Guru (224K reputation)SSC Guru (224K reputation)SSC Guru (224K reputation)SSC Guru (224K reputation)

Group: General Forum Members
Points: 224667 Visits: 46320
That table doesn't have either of the columns bizState or bizCity.

With that definition, the query is going to give an Invalid column error because the two columns are not in the table.

Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


Lowell
Lowell
SSC Guru
SSC Guru (71K reputation)SSC Guru (71K reputation)SSC Guru (71K reputation)SSC Guru (71K reputation)SSC Guru (71K reputation)SSC Guru (71K reputation)SSC Guru (71K reputation)SSC Guru (71K reputation)

Group: General Forum Members
Points: 71834 Visits: 40942
i don't see biz.city or biz.state in this definition:

CREATE TABLE [dbo].[shops](
[bizID] [int] IDENTITY(1,1) NOT NULL,
[bizName] [nvarchar](255) NULL,
[bizPhone] [nvarchar](15) NULL,
[bizURL] [nvarchar](500) NULL,
[bizLogo] [nvarchar](max) NULL,
[clicks] [int] NULL,
[clickReset] [datetime] NULL,
[clickTotal] [int] NULL,
[bizActive] [bit] NOT NULL,
[bizCreated] [datetime] NULL,
[bizRate] [decimal](18, 0) NULL,
[lastPayment] [datetime] NULL,
[userID] [uniqueidentifier] NULL,
[contactName] [nvarchar](250) NULL,
[contactEmail] [nvarchar](250) NULL,
CONSTRAINT [PK_shops] PRIMARY KEY CLUSTERED
(
[bizID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]





Lowell
--help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!
dcwhitson
dcwhitson
SSC Rookie
SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)

Group: General Forum Members
Points: 29 Visits: 3
They were added to the new table in the new database after it was scripted. That's where I said I re-built the database manually two times, no scripting, but actually going through and creating each column (including the city and state columns), type etc.

I am in the process of starting a new project in web developer and see how far I can get so I can figure out where the hitch is.
GilaMonster
GilaMonster
SSC Guru
SSC Guru (224K reputation)SSC Guru (224K reputation)SSC Guru (224K reputation)SSC Guru (224K reputation)SSC Guru (224K reputation)SSC Guru (224K reputation)SSC Guru (224K reputation)SSC Guru (224K reputation)

Group: General Forum Members
Points: 224667 Visits: 46320
dcwhitson (1/12/2012)
They were added to the new table in the new database after it was scripted. That's where I said I re-built the database manually two times, no scripting, but actually going through and creating each column (including the city and state columns), type etc.


But the table that you scripted for me (which I assume is the actual, latest, real table that you are using) doesn't have them. Was that the new table in the new database? If so, the columns aren't there. If it wasn't, please post the CREATE TABLE statement for the actual, real shops table that you are running that query against

I am in the process of starting a new project in web developer and see how far I can get so I can figure out where the hitch is.


No, don't. There's a logical explanation here, trashing and restarting could just waste time.

Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search