View Works, But The Sql From The View Does Not
Oct 27, 2006
I was looking through our vendors views, searching for something I
needed for our Datawarehouse and I came across something I do not
understand: I found a view that lists data when I use it in t-sql,
however when I try to use the statement when I modified the view (via
MS SQL Server Management Studio) I can not execute the statement. I get
The column prefix 'dbo.tbl_5001_NumericAudit' does not match with a
table name or alias name used in the query.
Upon closer inspection, I found two ON for the inner join, which I dont
think is correct.
So, how can the view work, but not the SQL that defines the view?
SQL Server 2000, up to date patches:
SELECT dbo.tbl_5001_NumericAudit.aEventID,
dbo.tbl_5001_NumericAudit.nParentEventID,
dbo.tbl_5001_NumericAudit.nUserID,
dbo.tbl_5001_NumericAudit.nColumnID,
dbo.tbl_5001_NumericAudit.nKeyID,
dbo.tbl_5001_NumericAudit.dChangeTime,
CAST(dbo.tbl_5001_NumericAudit.vToValue AS
nVarchar(512)) AS vToValue, dbo.tbl_5001_NumericAudit.nChangeMode,
dbo.tbl_5001_NumericAudit.tChildEventText, CASE
WHEN nConstraintType = 3 THEN 5 ELSE tblColumnMain.nDataType END AS
nDataType,
dbo.tbl_5001_NumericAudit.nID,
CAST(dbo.tbl_5001_NumericAudit.vFromValue AS nVarchar(512)) AS
vFromValue
FROM dbo.tbl_5001_NumericAudit WITH (NOLOCK) LEFT OUTER JOIN
dbo.tblColumnMain WITH (NoLock) INNER JOIN
--
-- Posters comment: here is the double ON
--
dbo.tblCustomField WITH (NoLock) ON
dbo.tblColumnMain.aColumnID = dbo.tbl_5001_NumericAudit.nColumnID ON
dbo.tbl_5001_NumericAudit.nColumnID =
dbo.tblCustomField.nColumnID LEFT OUTER JOIN
dbo.tblConstraint WITH (NOLOCK) ON
dbo.tblCustomField.nConstraintID = dbo.tblConstraint.aConstraintID AND
(dbo.tblConstraint.nConstraintType = 4 OR
dbo.tblConstraint.nConstraintType = 9 OR
dbo.tblConstraint.nConstraintType = 3)
UNION ALL
SELECT aEventID, nParentEventID, nUserID, nColumnID, nKeyID,
dChangeTime, CAST(CAST(vToValue AS decimal(19, 6)) AS nVarchar(512)) AS
vToValue,
nChangeMode, tChildEventText, 5 AS nDataType,
nID, CAST(CAST(vFromValue AS decimal(19, 6)) AS nVarchar(512)) AS
vFromValue
FROM dbo.tbl_5001_FloatAudit WITH (NOLOCK)
UNION ALL
SELECT aEventID, nParentEventID, nUserID, nColumnID, nKeyID,
dChangeTime, CAST(vToValue AS nVarchar(512)) AS vToValue, nChangeMode,
tChildEventText, 2 AS nDataType, nID,
CAST(vFromValue AS nVarchar(512)) AS vFromValue
FROM dbo.tbl_5001_StringAudit WITH (NOLOCK)
UNION ALL
SELECT aEventID, nParentEventID, nUserID, nColumnID, nKeyID,
dChangeTime, CONVERT(nVarchar(512), vToValue, 121) AS vToValue,
nChangeMode,
tChildEventText, 3 AS nDataType, nID,
CONVERT(nVarchar(512), vFromValue, 121) AS vFromValue
FROM dbo.tbl_5001_DateAudit WITH (NOLOCK)
View 1 Replies
ADVERTISEMENT
Jun 29, 2007
I have an application that utilizes aspnet for membership.
The application utilizes the same database (in SQLServer) for storage of other things. I have a view as follows:
USE [DB_Name]
GO
/****** Object: View [dbo].[Authorization] Script Date: 06/29/2007 15:27:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW Authorization
AS
SELECT dbo.Domain.Domain_ID, dbo.Domain.Domain_Name, dbo.Alias.Alias_Name,
dbo.Alias.Alias_Authority, dbo.Domain.Domain_ProcessType, dbo.Domain.Domain_Status,
dbo.aspnet_Users.UserName AS Owner_Name
FROM dbo.Alias INNER JOIN
dbo.Domain ON dbo.Alias.Alias_Parent_ID = dbo.Domain.Domain_ID INNER JOIN
dbo.aspnet_Users ON dbo.Domain.Domain_Owner_ID = dbo.aspnet_Users.UserId
This works fine locally. However, I am hosting this on GoDaddy and though it allows me to create the table, it seems to have a problem (I'm guessing because it is referencing differing schemas?) and I get an error of: Incorrect syntax near the keyword 'Authorization'.through the SQLServer Web interface whenever I attempt to view the data from this view.
I don't doubt that there is some kind of difference between the manner that SQLServer has set up the schemas and how they are set up on my local version.
Any help would be greatly appreciated. I am at a loss of how to get this info and truly want to utilize the view as it would improve performance over a query - at least I believe so. My thinking is that although there may be a performance drop when the item is being added, I gain on the back-end where I really need the performance over utilizing a query.
Thanks,
Steven Henley
View 3 Replies
View Related
Jan 22, 2008
I created a data model for report builder. And since it wont let me use views, i tried to put all the tables im using in one of my already made views, to create a data source view like my sql view. But when i connect everything the same, my report model still doesnt narrow my search. I only want to see Breed information, but since i have a Breeder table,and Customer table, its showing me all customers, and not limiting it to the ones that are breeder customers.
heres the tables:
Code Snippet
FROM dbo.Tbl_Customer INNER JOIN
dbo.Tbl_Customer_Breeder ON dbo.Tbl_Customer.Customer_Code = dbo.Tbl_Customer_Breeder.Customer_Code INNER JOIN
dbo.Tbl_Customer_Detail ON dbo.Tbl_Customer.Customer_Code = dbo.Tbl_Customer_Detail.Customer_Code INNER JOIN
dbo.Tbl_Customer_Category ON dbo.Tbl_Customer.Customer_Category_Id = dbo.Tbl_Customer_Category.Customer_Category_Id INNER JOIN
dbo.Tbl_Customer_Classification ON
dbo.Tbl_Customer.Customer_Classification_Id = dbo.Tbl_Customer_Classification.Customer_Classification_Id INNER JOIN
dbo.Tbl_Customer_In_Breed ON dbo.Tbl_Customer.Customer_Code = dbo.Tbl_Customer_In_Breed.Customer_Code INNER JOIN
dbo.Tbl_Breed ON dbo.Tbl_Customer_In_Breed.Breed_Id = dbo.Tbl_Breed.Breed_Id
What am i doing wrong, and are there any suggestions.
View 6 Replies
View Related
Oct 17, 2006
This one has me stumped.
I created an updateable partioned view of a very large table. Now I get an error when I attempt to declare a CURSOR that SELECTs from the view, and a FOR UPDATE argument is in the declaration.
There error generated is:
Server: Msg 16957, Level 16, State 4, Line 3
FOR UPDATE cannot be specified on a READ ONLY cursor
Here is the cursor declaration:
declare some_cursor CURSOR
for
select *
from part_view
FOR UPDATE
Any ideas, guys? Thanks in advance for knocking your head against this one.
PS: Since I tested the updateability of the view there are no issues with primary keys, uniqueness, or indexes missing. Also, unfortunately, the dreaded cursor is requried, so set based alternatives are not an option - it's from within Peoplesoft.
View 2 Replies
View Related
Jul 23, 2005
I am looking to create a constraint on a table that allows multiplenulls but all non-nulls must be unique.I found the following scripthttp://www.windowsitpro.com/Files/0.../Listing_01.txtthat works fine, but the following lineCREATE UNIQUE CLUSTERED INDEX idx1 ON v_multinulls(a)appears to use indexed views. I have run this on a version of SQLStandard edition and this line works fine. I was of the understandingthat you could only create indexed views on SQL Enterprise Edition?
View 3 Replies
View Related
Jul 24, 2012
Write a CREATE VIEW statement that defines a view named Invoice Basic that returns three columns: VendorName, InvoiceNumber, and InvoiceTotal. Then, write a SELECT statement that returns all of the columns in the view, sorted by VendorName, where the first letter of the vendor name is N, O, or P.
This is what I have so far,
CREATE VIEW InvoiceBasic AS
SELECT VendorName, InvoiceNumber, InvoiceTotal
From Vendors JOIN Invoices
ON Vendors.VendorID = Invoices.VendorID
[code]...
View 2 Replies
View Related
Aug 24, 2007
Hi guys 'n gals,
I created a query, which makes use of a temp table, and I need the results to be displayed in a View. Unfortunately, Views do not support temp tables, as far as I know, so I put my code in a stored procedure, with the hope I could call it from a View....
I tried:
CREATE VIEW [qryMyView]
AS
EXEC pr_MyProc
and unfortunately, it does not let this run.
Anybody able to help me out please?
Cheers!
View 3 Replies
View Related
Mar 9, 2006
I compared view query plan with query plan if I run the same statementfrom view definition and get different results. View plan is moreexpensive and runs longer. View contains 4 inner joins, statisticsupdated for all tables. Any ideas?
View 10 Replies
View Related
Aug 14, 2000
I had given one of our developers create view permissions, but he wants to also modify views that are not owned by him, they are owned by dbo.
I ran a profiler trace and determined that when he tries to modify a view using query designer in SQLem or right clicks in SQLem on the view and goes to properties, it is performing a ALTER VIEW. It does the same for dbo in a trace (an ALTER View). He gets a call failed and a permission error that he doesn't have create view permissions, object is owned by dbo, using both methods.
If it is doing an alter view how can I set permissions for that and why does it give a create view error when its really doing an alter view? Very confusing.
View 1 Replies
View Related
Feb 17, 2006
I have this view in SQL server:
CREATE VIEW dbo.vwFeat
AS
SELECT dbo.Lk_Feat.Descr, dbo.Lk_Feat.Price, dbo.Lk_Feat.Code, dbo.SubFeat.SubNmbr
FROM dbo.Lk_Feat INNER JOIN
dbo.SubFeat ON dbo.Lk_Feat.Idf = dbo.SubFeat.Idt
When ever I open using SQL Entreprise manager to edit it by adding or removing a field i inserts Expr1,2.. and I don t want that. The result I get is:
SELECT dbo.Lk_Feat.Descr AS Expr1, dbo.Lk_Feat.Price AS Expr2, dbo.Lk_Feat.Code AS Expr3, dbo.SubFeat.SubNmbr AS Expr4
FROM dbo.Lk_Feat INNER JOIN
dbo.SubFeat ON dbo.Lk_Feat.Idf = dbo.SubFeat.Idt
I don t want Entreprise manager to generate the Expr fields since I use the real fields in my application.
Thanks for help
View 4 Replies
View Related
Feb 21, 2006
A colleague of mine has a view that returns approx 100000 rows in about 60 seconds.
He wants to use the data returned from that view in an OLE DB Source component.
When he selects the view from the drop-down list of available tables then SSIS seems to hang without any data being returned (he waited for about 15 mins).
He then changed the OLE DB Source component to use a SQL statement and the SQL statement was: SELECT * FROM <viewname>
In this instance all the data was returned in approx 60 seconds (as expected).
This makes no sense. One would think that selecting a view from the drop-down and doing a SELECT *... from that view would be exactly the same. Evidently that isn't the case.
Can anyone explain why?
Thanks
-Jamie
View 2 Replies
View Related
Mar 29, 2007
I need to create a view that will look at payments made by clients and show me the clients that made payments last year but not this year.
tblPayments (ClientID, PmtID, PmtDate, PmtAmt)
How would I set the criteria for this?
View 1 Replies
View Related
Feb 7, 2008
How do I set up a sql statement to use as a view?
I want to use two tables but they are both from different databases.
From the Offices database I want to use a table called Office Code and only the Name column
The other database is called Library and I want to use a table called Requestors and join it to others.
I've set the stored procedure up that I want to use to get most of the data besides the data in the offices database.
Create view GetDataview
select requestors.officeCode, requestors.Fname + ' ' + requestors.Lname as [Name], Titles.title as Title from requestors
join libraryrequest on libraryrequest.requestorid = requestors.requestoridjoin Titles on Titles.Titleid = libraryrequest.Titleidwhere officecode <> 0order by OfficecodeGO How do I add the database offices, table officecodes to this view to use the Name column?
I hope this makes sense
View 6 Replies
View Related
May 18, 2008
how can i make a view in my sqlexpress 2005 database that get data from oracle database or from RDB (old oracle database)
View 6 Replies
View Related
May 18, 2001
I am trying to write a view to retrieve data from
two different servers..
create view as
select c1 from ser1.database1.dbo.table1
union
select 1 from ser2.database2.dbo.table1
First it is not accepting to write it from EM, hence I wrote it from QA,
the problem when I am trying to execute it is giving following error
"Could not find server 'hercules' in sysservers"
Help me out what needs to be done?
View 2 Replies
View Related
Jan 12, 2001
i need to create a view for a table which is residing on another remote server how to do this could u guide me with the process and give me an example.
ur help is appriciated.
View 1 Replies
View Related
Sep 21, 2000
I have a view which I am supposed to run manually first thing tomorrow morning but I will not be
in tomorrow. Is it possible for me to schedule it as a job to run tomorrow.
View 1 Replies
View Related
May 7, 2002
How many maximum number of tables I can used to create the view in SQL 6.5..?
View 1 Replies
View Related
Oct 24, 2007
When I ran this SQL Query, I got an unexpected result.
//Sql Query
Code:
SELECT distinct Year FROM vw_EMD_Options_Pricing WHERE (Year >= '2003') AND (Year <= '2008')
The view is the "vw_EMD_Options_Pricing". The request I got is the year that go from 1981 to 2008. This is for MS-SQL 2000. Why does the SQL Query does that?
View 2 Replies
View Related
Oct 20, 2004
I have a database with a view to another table in another database which I created a form out of. I was wondering when if this rule applies
"Data Entry" property of the form is set to True. The default value for this property is "False" which means that Access opens the form and shows the existing records. However, if set to True, the Data Entry property of the form specifies that the form will only show a blank record.
The reason I am asking is because you cant see the records after you close the form and reopen it again.
View 1 Replies
View Related
Apr 6, 2007
Hi,
I have 2 databases, db1, db2 in the SQL Server. In db1, I created the view to link one table from db2. When I run it, it is just read-only, I want to edit/insert data in the view. Can we edit/insert the data in the view from db1(which linked table from db2)?
View 1 Replies
View Related
May 18, 2004
Hello Everyone,
When I write a sql joining more than views how will be executed?.
Does SQL Server execute each view and join the result set or interpret into one final sql and execute?
Thanks
Masanam
View 3 Replies
View Related
Apr 22, 2008
Hello All,
My sample data looks like this in SQL Server 2000
SubGr,Trno,Glcode,Amount,DrCr
----------------------------
Bank,1000,100001,1000.00,D
Other,1000,100012,1000.00,C
Other,1001,100010,1500.00,D
Other,1001,100010,1500.00,D
Bank,1001,100002,3000.00,C
Bank,1002,100001,2000.00,D
Bank,1002,100003,2000.00,C
Other,1003,100051,5000.00,D
Other,1003,100051,5000.00,C
I want a view which gives a output like this for those SubGr with 'Bank'.
Output
SubGr,Trno,Glcode,Amount,DrCr,Bank
----------------------------------
Other,1000,100012,1000.00,C,100001
Other,1001,100010,1500.00,D,100002
Other,1001,100010,1500.00,D,100002
Bank,1002,100001,2000.00,D,100003
Bank,1002,100003,2000.00,C,100001
Thanks in anticipation
Nirene
View 4 Replies
View Related
May 5, 2008
I want to create a view that has an if then statement within it, how is this done?
View 5 Replies
View Related
May 16, 2008
Hi,
I have a view in my database which returns:
ID Date Area
1010712008F
1020712008F
1030712008F
I should change this view’s output in such a way that for each Id I should have 3 record:
IDDateAreaType
1010712008FLO
1010712008FPO
1010712008FSO
1020712008FLO
1020712008FPO
1020712008FSO
1030712008FLO
1030712008FPO
1030712008FSO
LO ,PO and SO are constant.
How should I do that?
Thanks.
View 5 Replies
View Related
Jun 3, 2008
i have a view that calls 4-5 functions and many joins,
the time to display data is around 10-11 mins,
how can i improve performance?
View 4 Replies
View Related
Jun 10, 2008
I have a small doubt.
Can we update a table through view.
Is there any limitation to upadate
View 1 Replies
View Related
Oct 31, 2005
Hi
How can i save a query as a view if query contains the case statement
asm
View 2 Replies
View Related
Mar 31, 2006
I've never worked with views before though I have a vaugue idea what they're for :)
I have a table that is quite large and growing fast and my primary use for the data is to run lots of aggregate functions on it.
See my previous post for an example:
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=63748
Queries like that are taking 10 seconds to run.
So what I'm looking for is a way to store the results of a query like that, run the actual query maybe once an hour, and any time a user needs that data they get the results of the last run.
My first thought was to just have "summary" tables that get updated by a Stored Procudure that runs on a schedule under "Jobs". Is there a better way?
Thanks!
Edit: Some of the "summary" data would be based on date, so the summarized data would only need to be processed once. Don't know if that is something to consider.
View 2 Replies
View Related
Sep 19, 2006
Shahbaz writes "Hi
1.Can we delete the record using view.?
2.Can we insert and update the record through view?
Thanks and Regards,
Shahbaz"
View 5 Replies
View Related
Feb 2, 2007
Hey Guys,
I am trying to get 5 days back date and in my table the following 3 records are there but my query is not pulling. Could you please tell me what is wrong with my query? Thanks
select * from
dbo.tblTransaction
WHERE Performance_dm >= dateadd(day, datediff(day, 0, getdate()), - 5) AND Performance_dm < dateadd(day, datediff(day, 0, getdate()), -4)
order by Performance_dm
These are the records in the table but it is not pulling. How should i pull these records please?
2007-01-28 00:01:00.000
2007-01-28 00:01:00.000
2007-01-28 00:01:00.000
View 2 Replies
View Related
Feb 11, 2007
I have tried Books online and have queried this forum for assistance in creating a SQL view and have spent much time trying to solve on my own.
I am working with only one table:
Sales: SOP10200
SOPTYPE ITEMNMBR ITEMDESC QUANTITY
3 Widget special 4
3 Widget special 7
2 Gadget special 1
2 Widget special 12
3 Gadget special 5
I want to create a view that summarizes the data based upon SOPTYPE and ITEMNMBR as follows:
ITEM_NUMBER ITEM_DESC QTY_INVOICED QTY_ORDERED
Widget special 11 12
Gadget special 5 1
I am struggling whether to use a select statement or a CASE statement.
I am able to summarize one SOPTYPE as follows:
CREATE VIEW [dbo].[Tec_SOP10200_INVOICE_Qty]
AS
SELECT ITEMNMBR as ITEM_NUMBER, ITEMDESC as ITEM_DESC, SUM(QUANTITY) AS QTY_INVOICED
FROM SOP10200
WHERE SOPTYPE = 3
GROUP BY ITEMNMBR, ITEMDESC
But I need more than one soptype in same view
I tried this CASE statement -
Create tec_sales_view
as
SELECT SOP10200.ITEMNMBR as ITEM_NUMBER
, SOP10200.ITEMDESC as ITEM_DESC
, SOP10200.QTY1 'QTY_INVOICED'
, SOP10200.QTY2 'QTY_ORDERED'
, (CASE
WHEN SOP10200.SOPTYPE = 3 THEN SUM(QUANTITY) QTY1 ELSE 0)
(CASE
WHEN SOP10200.SOPTYPE = 2 THEN SUM(QUANTITY) QTY2 ELSE 0)
END as QTY_Type
FROM SOP10200
GROUP BYITEMNMBR, ITEMDESC, QTY1, QTY2
But I get error message doesn't recognize QTY1 (invalid column name)
Thank you in advance for any assistance.......
View 2 Replies
View Related
Jul 23, 2005
I am doing a monthly report to export to an excel Doc from SQL 2000using views.With my design it works great until it is the first of the month. As thereport alwayschecks from yesterday to the first of the current month. One view is below.The date statement checks between the first of month and current date -1Can anyone help with with this?MikeCREATE VIEW dbo.GUTURASSELECT COUNT(*) AS GUTURFROM dbo.ChevWHERE ([Deal Date] BETWEEN DATEADD(mm, DATEDIFF(mm, 0, GETDATE()), 0)AND GETDATE() - 1) AND ([N/U] = 'U') AND (([Sales Type] = 'R') or ([SalesType] = '3'))
View 1 Replies
View Related