Friday, March 23, 2012

problem with a view

We have a view called "vwtblBranchData" which is this: "SELECT *
FROM Branch_Master.dbo.tblBranchData"
We have a query that uses the view that has worked for over a year and now
has stopped working. The query is: select * from vwtblBranchData with
(readuncommitted) where (closed=0) and branch_num between 2000 and 2939 orde
r
by branch_num.
If I run just "select * from vwtblBranchData" or "select * from
vwtblBranchData where branch_num between 2000 and 2939 order by branch_num",
it works but when I add the "closed=0" part, it won't work. The closed colum
n
is a bit and is populated with only 0 or 1 in the table.
If I take the view out and run: "select * from branch_master..tblBranchData
with (readuncommitted) where (closed=0) and branch_num between 2000 and 2939
order by branch_num", it works.
Any idea what is happening?
Thanks,
Dan D.I put the query - "select * from vwtblBranchData where closed = 0 and
branch_num between 2000 and 2939 order by branch_num" in the query analyzer
and saw this: WHERE (([tblBranchData].[ActivePest]=0 AND
Convert([tblBranchData].[Branch_num])<=2939 AND
Convert([tblBranchData].[Branch_num])>=2000) ORDERED FORWARD
The "ActivePest" column isn't in the query or the view. Any idea where that
came from?
"Dan D." wrote:

> We have a view called "vwtblBranchData" which is this: "SELECT *
> FROM Branch_Master.dbo.tblBranchData"
> We have a query that uses the view that has worked for over a year and now
> has stopped working. The query is: select * from vwtblBranchData with
> (readuncommitted) where (closed=0) and branch_num between 2000 and 2939 or
der
> by branch_num.
> If I run just "select * from vwtblBranchData" or "select * from
> vwtblBranchData where branch_num between 2000 and 2939 order by branch_num
",
> it works but when I add the "closed=0" part, it won't work. The closed col
umn
> is a bit and is populated with only 0 or 1 in the table.
> If I take the view out and run: "select * from branch_master..tblBranchDat
a
> with (readuncommitted) where (closed=0) and branch_num between 2000 and 29
39
> order by branch_num", it works.
> Any idea what is happening?
> Thanks,
>
> --
> Dan D.|||Could you please tell us the error you are getting? At this point we don't
even know what is happening on your side :)
----
Louis Davidson - drsql@.hotmail.com
SQL Server MVP
Compass Technology Management - www.compass.net
Pro SQL Server 2000 Database Design -
http://www.apress.com/book/bookDisplay.html?bID=266
Blog - http://spaces.msn.com/members/drsql/
Note: Please reply to the newsgroups only unless you are interested in
consulting services. All other replies may be ignored :)
"Dan D." <DanD@.discussions.microsoft.com> wrote in message
news:DCFD1C2F-6C74-47AE-B53E-588405749CD4@.microsoft.com...
> We have a view called "vwtblBranchData" which is this: "SELECT *
> FROM Branch_Master.dbo.tblBranchData"
> We have a query that uses the view that has worked for over a year and now
> has stopped working. The query is: select * from vwtblBranchData with
> (readuncommitted) where (closed=0) and branch_num between 2000 and 2939
> order
> by branch_num.
> If I run just "select * from vwtblBranchData" or "select * from
> vwtblBranchData where branch_num between 2000 and 2939 order by
> branch_num",
> it works but when I add the "closed=0" part, it won't work. The closed
> column
> is a bit and is populated with only 0 or 1 in the table.
> If I take the view out and run: "select * from
> branch_master..tblBranchData
> with (readuncommitted) where (closed=0) and branch_num between 2000 and
> 2939
> order by branch_num", it works.
> Any idea what is happening?
> Thanks,
>
> --
> Dan D.|||Suspect a schema or metadata change. Try recreating the view. However, the
best approach is to specify the columns you want to select, rather than use
the wildcard.
"Dan D." <DanD@.discussions.microsoft.com> wrote in message
news:DCFD1C2F-6C74-47AE-B53E-588405749CD4@.microsoft.com...
> We have a view called "vwtblBranchData" which is this: "SELECT *
> FROM Branch_Master.dbo.tblBranchData"
> We have a query that uses the view that has worked for over a year and now
> has stopped working. The query is: select * from vwtblBranchData with
> (readuncommitted) where (closed=0) and branch_num between 2000 and 2939
order
> by branch_num.
> If I run just "select * from vwtblBranchData" or "select * from
> vwtblBranchData where branch_num between 2000 and 2939 order by
branch_num",
> it works but when I add the "closed=0" part, it won't work. The closed
column
> is a bit and is populated with only 0 or 1 in the table.
> If I take the view out and run: "select * from
branch_master..tblBranchData
> with (readuncommitted) where (closed=0) and branch_num between 2000 and
2939
> order by branch_num", it works.
> Any idea what is happening?
> Thanks,
>
> --
> Dan D.|||Sorry. The query wasn't returning any rows when it should have. I solved the
problem. The query analyzer was trying to use the "active_pest". We didn't
need the column so I removed it and the query worked.
Thanks.
"Louis Davidson" wrote:

> Could you please tell us the error you are getting? At this point we don'
t
> even know what is happening on your side :)
> --
> ----
--
> Louis Davidson - drsql@.hotmail.com
> SQL Server MVP
> Compass Technology Management - www.compass.net
> Pro SQL Server 2000 Database Design -
> http://www.apress.com/book/bookDisplay.html?bID=266
> Blog - http://spaces.msn.com/members/drsql/
> Note: Please reply to the newsgroups only unless you are interested in
> consulting services. All other replies may be ignored :)
> "Dan D." <DanD@.discussions.microsoft.com> wrote in message
> news:DCFD1C2F-6C74-47AE-B53E-588405749CD4@.microsoft.com...
>
>|||I solved the problem. The query analyzer was trying to use the "active_pest"
.
We didn't need the column so I removed it and the query worked.
Thanks.
"Scott Morris" wrote:

> Suspect a schema or metadata change. Try recreating the view. However, t
he
> best approach is to specify the columns you want to select, rather than us
e
> the wildcard.
> "Dan D." <DanD@.discussions.microsoft.com> wrote in message
> news:DCFD1C2F-6C74-47AE-B53E-588405749CD4@.microsoft.com...
> order
> branch_num",
> column
> branch_master..tblBranchData
> 2939
>
>sql

No comments:

Post a Comment