| Author |
Topic |
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2007-05-01 : 16:35:02
|
Hi, I did some searching but I am not seeing my issue addressed. I have a view in one DB that points to a table in another DB both on the same server. However, the view shows a particular column as INT when it is defined as NVARCHAR(9) in the base table. Any know how to get the view to show the correct data type?For example:-- Source TableCREATE TABLE dbo.Foo( FooId int NOT NULL, FooName nvarchar(255) NOT NULL, AddressLine1 nvarchar(255) NULL, AddressLine2 nvarchar(255) NULL, AddressLine3 nvarchar(255) NULL, City nvarchar(255) NULL, StateOrProvince nvarchar(50) NULL, PostalCode nvarchar(50) NULL, Country nvarchar(255) NULL, FooNumber nvarchar(9) NULL)GO-- ViewCREATE VIEW dbo.FooASSELECT FooId, FooName, AddressLine1, AddressLine2, AddressLine3, City, StateOrProvince, PostalCode, Country, FooNumberFROM SourceDB.dbo.Foo WITH (NOLOCK)GO When I look at the view in Management Studio it shows FooNumber as an INT. Additionally, if I select from the view I get INT values out of FooNumber.If anyone has any ideas, please pass them along.Thanks,-Ryan |
|
|
dinakar
Master Smack Fu Yak Hacker
2507 Posts |
Posted - 2007-05-01 : 16:36:58
|
| did you alter the table recently? drop/recreate the view and see if it makes any difference.Dinakar NethiSQL Server MVP************************Life is short. Enjoy it.************************http://weblogs.sqlteam.com/dinakar/ |
 |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2007-05-01 : 16:38:35
|
quote: Originally posted by dinakar did you alter the table recently? drop/recreate the view and see if it makes any difference.
Yeah, I've done that several times trying to figure out what is going on. |
 |
|
|
dinakar
Master Smack Fu Yak Hacker
2507 Posts |
Posted - 2007-05-01 : 16:43:24
|
| was the table on the SourceDB altered recently?Dinakar NethiSQL Server MVP************************Life is short. Enjoy it.************************http://weblogs.sqlteam.com/dinakar/ |
 |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2007-05-01 : 16:46:21
|
quote: Originally posted by dinakar was the table on the SourceDB altered recently?
Yes. The issues existed and I tried several things to try resolve it. One of the things I did was to drop and recreate the offending column. |
 |
|
|
dinakar
Master Smack Fu Yak Hacker
2507 Posts |
Posted - 2007-05-01 : 17:01:21
|
| drop/recreate the view. Views are not automaticaly refreshed when underlying schema changes.Dinakar NethiSQL Server MVP************************Life is short. Enjoy it.************************http://weblogs.sqlteam.com/dinakar/ |
 |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2007-05-01 : 18:00:21
|
quote: Originally posted by dinakar drop/recreate the view. Views are not automaticaly refreshed when underlying schema changes.
Yep, as mentioned above, I did drop and re-create the view several times. The thing that is strange is that the column that is having the issue has alwasy been NVARCHAR(9). |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-05-01 : 18:09:58
|
| [code]CREATE VIEW dbo.FooASSELECT FooId, FooName, AddressLine1, AddressLine2, AddressLine3, City, StateOrProvince, PostalCode, Country, CAST(FooNumber AS NVARCHAR(9)) AS FooNumberFROM SourceDB.dbo.Foo WITH (NOLOCK)[/code]Peter LarssonHelsingborg, Sweden |
 |
|
|
dinakar
Master Smack Fu Yak Hacker
2507 Posts |
Posted - 2007-05-01 : 18:13:07
|
quote: Originally posted by Peso
CREATE VIEW dbo.FooASSELECT FooId, FooName, AddressLine1, AddressLine2, AddressLine3, City, StateOrProvince, PostalCode, Country, CAST(FooNumber AS NVARCHAR(9)) AS FooNumberFROM SourceDB.dbo.Foo WITH (NOLOCK) Peter LarssonHelsingborg, Sweden
Peso, thats like beating it with a stick.Dinakar NethiSQL Server MVP************************Life is short. Enjoy it.************************http://weblogs.sqlteam.com/dinakar/ |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-05-01 : 18:16:28
|
| I know. It only hides the symptom.Peter LarssonHelsingborg, Sweden |
 |
|
|
|