Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

'Invalid Column Name' Error Expand / Collapse
Author
Message
Posted Thursday, January 12, 2012 1:06 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, January 12, 2012 3:30 PM
Points: 3, 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...
Post #1235195
Posted Thursday, January 12, 2012 1:22 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 6:44 AM
Points: 39,983, Visits: 36,351
Can you post the CREATE TABLE statement for the Shops table please?


Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
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

Post #1235202
Posted Thursday, January 12, 2012 2:24 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, January 12, 2012 3:30 PM
Points: 3, 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
Post #1235242
Posted Thursday, January 12, 2012 3:26 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 6:44 AM
Points: 39,983, Visits: 36,351
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 2008, MVP
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

Post #1235274
Posted Thursday, January 12, 2012 3:27 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 2:07 AM
Points: 12,903, Visits: 32,145
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

--There is no spoon, and there's no default ORDER BY in sql server either.
Actually, Common Sense is so rare, it should be considered a Superpower. --my son
Post #1235275
Posted Thursday, January 12, 2012 3:34 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, January 12, 2012 3:30 PM
Points: 3, 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.
Post #1235279
Posted Thursday, January 12, 2012 3:39 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 6:44 AM
Points: 39,983, Visits: 36,351
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 2008, MVP
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

Post #1235281
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse