Showing posts with label view. Show all posts
Showing posts with label view. Show all posts

Thursday, March 22, 2012

Can't find Folders that I hid in List View

To all,

I checked the box "hide in list view" for a particular folder under the folder properties. Does anybody know how I get my folder back in the list view again? I cannot seem to find any information pertaining to "unhiding" a folder that was hidden.

Thank you,

blyonsd

In Report Manager, get to a level one above the Folder (where you would have seen it if not hidden ...). Click Show Details on the upper right bar. When the folder appears in the list, re-enter it, go to the Properties tab, and uncheck Hide in list view. Apply, and it should re-appear with Details Hidden ...

Good Luck.

Bill

William E. Pearson III
CPA, CMA, CIA, MCSE, MCDBA
Island Technologies Inc.
931 Monroe Drive
Suite 102-321
Atlanta, GA 30308

404.872.5972 Office

wep3@.islandtechnologies.com

wep3@.reporting-services-architect.com
www.reporting-services-architect.com
-- -- --

Publisher Sites:

http://www.databasejournal.com/article.php/1459531

http://www.sql-server-performance.com/bill_pearson.asp

http://www.informit.com/authors/bio.asp?a=862acd62-4662-49ae-879d-541c8b4d656f

http://www.2000trainers.com/section.aspx?sectionID=17

|||Thank you very much for your help!! It worked like a charm.

Tuesday, March 20, 2012

Can't execute View script using SMO

Hi !

I have another problem. Here is now what i'm doing:
Dim unTransfert As New Transfer(BDConfig)
unTransfert.CopyAllObjects = True

unTransfert.DropDestinationObjectsFirst = True
unTransfert.CopySchema = True
unTransfert.CopyData = False
unTransfert.Options.ContinueScriptingOnError = True
unTransfert.DestinationServer = ServeurLocal.Name.ToString
unTransfert.DestinationDatabase = NouvelleBD.Name.ToString
unTransfert.Options.IncludeIfNotExists = True
NouvelleBD.ExecuteNonQuery(unTransfert.ScriptTransfer())

This failed because of my views. If i tried to copy tables only it's working fine. I've tried to copy one by one the view and then i notice that most of then failed and i think i know the reason but i don't know what to do. I've notice that the view that failed are view where the SELECT contain other view. Since those view are not created yet i've got those error. This is a big problem. We have over 300 views and i don't know which one need which one.
Is it possible to copy the views without having this kind of problem ?

Thanks !This is the first time i'm using SMO so i'm probably making some mistakes. Instead of doing this line:
NouvelleBD.ExecuteNonQuery(unTransfert.ScriptTransfer())

Now i'm doing this:
unTransfert.TransferData()

I still have the same problem. But i've notice something. If i add:
unTransfert.CopyAllObjects = false
unTransfert.CopyAllTables = True
unTransfert.CopyAllViews = True

After running for some seconds i've got an error saying it can create this view because this table doesn't exists. In fact the table exist in my BD but while doing the tranfer the views seems to be create before all the table are added. Did i do something wrong ? All i want is to copy all object from one BD to a new one and i need to do this online.

I've been working on this for 2 days and it still not working :-(....

Is someone have an idea of what i'm missing ?

Thanks !!

Thursday, March 8, 2012

Can't decompose a view on a view into one view

Sorry if that title is confusing.
Say I have a view on a table. And then say I build a view using that view.
Shouldn't I, theoretically, always be able to decompose a view built on
another view into a single view built on the underlying table(s)? I know
that SQL Server has to do this eventually. Obviously I'm doing something
wrong.
I'm trying to find the stock and fund "postions" (number of shares) for
client accounts as of a given date. We have all asset positions at the end
of each month, and then we get changed postitions whenever they change
during the month.
I know this is not a new problem, but I went ahead and wrote the SQL that I
thought would give the answer. Maybe I should have searched for the common
way of doing this. My real question is why can't I write this as one SQL
statement.
DDL is listed below. I started with a view that returns all end-of-January
positions plus all positions through the given date (which is only 3 days
later, February 3rd). The first view is here. I'm not gonna hard code
dates into my views in production; this is an experiment:
Create View Pos20050203 As
Select SSN_Tin, Acct_Number, Fund_ID, Position_Date, Quantity_ASD
From Positions Where Position_Date between '2005-01-31' and '2005-02-03'
Now that's simple enough. The next step is to find the latest position
date for each position:
SELECT SSN_Tin, Acct_Number, Fund_ID, MAX(Position_Date) AS LastPosDate
FROM Pos20050203
GROUP BY SSN_Tin, Acct_Number, Fund_ID)
The next step... Let me show you my final attempt at putting this into one
SQL statement and you can all flame me on what I'm doing wrong:
Select * From
(Select SSN_Tin, Acct_Number, Fund_ID, Position_Date, Quantity_ASD
From Positions
Where Position_Date between '2005-01-31' and '2005-02-03')
AS Pos20050203
Where Exists
(Select * From
(Select SSN_Tin, Acct_Number, Fund_ID, Max(Position_Date) AS LastPosDate
From Pos20050203
Group by SSN_Tin, Acct_Number, Fund_id) AS Derived
Where Derived.ssn_tin = Pos20050203.ssn_tin
And Derived.acct_number = Pos20050203.acct_number
And Derived.fund_id = Pos20050203.fund_id
And Derived.LastPosDate = Pos20050203.Position_Date)
I get "Invalid object name 'Pos20050203'." I wish QA would tell me WHICH
reference to this name is invalid; probably one in the last Where clause.
The table is certainly named a couple of steps earlier in the process.
How can this be fixed?
Oh, SSN_Tin is char(9), Acct_Number is varchar(20), Fund_ID is varchar(22),
Position_Date is datetime, and Quantity_asd is decimal.
Any help is appreciated.
David Walker...say I have a view on a table. And then say I build a view using
that view. Shouldn't I, theoretically, always be able to decompose a
view built on
another view into a single view built on the underlying table(s)?
...
that's not true. if you build and view then refer to that view in
another query, that's fine, because the first view has been complied.
if you just 'decompose' the first view in the 2nd query, it mgiht not
work. in ur case, the invalid object refers to this section...
Where Exists
(Select * From
(Select SSN_Tin, Acct_Number, Fund_ID, Max(Position_Date) AS
LastPosDate
>From Pos20050203
..
because Pos20050203 is in the same query, when sql executes the query,
it's not there yet.
if you use stored procedure and declare the temp table for the first
part of the query then it will work. (or you can create a view for the
first part)|||"DWalker" <none@.none.com> wrote in message
news:uImJFrRFFHA.1260@.TK2MSFTNGP12.phx.gbl...
> Sorry if that title is confusing.
> Say I have a view on a table. And then say I build a view using that
view.
> Shouldn't I, theoretically, always be able to decompose a view built on
> another view into a single view built on the underlying table(s)?

> Create View Pos20050203 As
> Select SSN_Tin, Acct_Number, Fund_ID, Position_Date, Quantity_ASD
> From Positions Where Position_Date between '2005-01-31' and '2005-02-03'
> SELECT SSN_Tin, Acct_Number, Fund_ID, MAX(Position_Date) AS LastPosDate
> FROM Pos20050203
> GROUP BY SSN_Tin, Acct_Number, Fund_ID)
Generally, just replace the viewname with the select that the view
represents.
Note that you must use an alias on the subquery.
So:
SELECT SSN_Tin, Acct_Number, Fund_ID, MAX(Position_Date) AS LastPosDate
FROM ( SELECT Select SSN_Tin, Acct_Number, Fund_ID, Position_Date,
Quantity_ASD
FROM Positions
WHERE Position_Date between '2005-01-31' and '2005-02-03') t
GROUP BY SSN_Tin, Acct_Number, Fund_ID
Good Luck,
Jim|||"James Goodwin" <jim.goodwin@.midmichigan.org> wrote in news:b424$4214e40a
$432498ca$26444@.allthenewsgroups.com:

> Generally, just replace the viewname with the select that the view
> represents.
Yes, but I hate repeating clauses, and sometimes I get parentheses in the
wrong places.
I now have this, and it works. (Pay no attention to the Select *)
Select * from
(Select * From PositionView Where Position_Date Between '2005-01-31' and
'2005-02-03') As PositionSlice
Where Exists
(Select * From
(Select SSN_Tin, Acct_Number, Fund_ID, Max(Position_Date) as LastDate
From PositionView
Where Position_Date Between '2005-01-31' and '2005-02-03'
Group by ssn_tin, acct_number, fund_id) As LastPos
Where PositionSlice.SSN_Tin = LastPos.SSN_Tin
And PositionSlice.Acct_Number = LastPos.Acct_Number
And PositionSlice.Fund_ID = LastPos.Fund_ID
And PositionSlice.Position_Date = LastPos.LastDate)
************
Question: Is there any way with table aliases to avoid repeating the
"Position_Date Between" clause in the query? I know it might not be
faster, but it will be simpler. I can't figure out how to do that.
Thanks.
David Walker|||"DWalker" <none@.none.com> wrote in message
news:euOEULSFFHA.3312@.TK2MSFTNGP15.phx.gbl...

> Select * from
> (Select * From PositionView Where Position_Date Between '2005-01-31' and
> '2005-02-03') As PositionSlice
> Where Exists
> (Select * From
> (Select SSN_Tin, Acct_Number, Fund_ID, Max(Position_Date) as LastDate
> From PositionView
> Where Position_Date Between '2005-01-31' and '2005-02-03'
> Group by ssn_tin, acct_number, fund_id) As LastPos
> Where PositionSlice.SSN_Tin = LastPos.SSN_Tin
> And PositionSlice.Acct_Number = LastPos.Acct_Number
> And PositionSlice.Fund_ID = LastPos.Fund_ID
> And PositionSlice.Position_Date = LastPos.LastDate)
Maybe Try something like this:
Select * from PositionView p
inner join (Select SSN_Tin, Acct_number, Fund_id,
Max(Position_Date) as lastdate
From positionView where Position_date
Between '20050131' and '20050203') l
on p.SSN_Tin = l.SSN_Tin
and p.Acct_number = l.Acct_number
and p.Fund_Id = l.Fund_Id
and p.Position_Date = l.LastDate
Good Luck,
Jim|||That doesn't work. See below...
"James Goodwin" <jim.goodwin@.midmichigan.org> wrote in
news:88153$4214fc66$432498ca$7045@.allthe
newsgroups.com:

> "DWalker" <none@.none.com> wrote in message
> news:euOEULSFFHA.3312@.TK2MSFTNGP15.phx.gbl...
>
>
> Maybe Try something like this:
> Select * from PositionView p
> inner join (Select SSN_Tin, Acct_number, Fund_id,
> Max(Position_Date) as lastdate
> From positionView where Position_date
> Between '20050131' and '20050203') l
> on p.SSN_Tin = l.SSN_Tin
> and p.Acct_number = l.Acct_number
> and p.Fund_Id = l.Fund_Id
> and p.Position_Date = l.LastDate
> Good Luck,
> Jim
>
Your suggestion returns these errors:
Server: Msg 8118, Level 16, State 1, Line 1
Column 'positionView.SSN_TIN' is invalid in the select list because it
is not contained in an aggregate function and there is no GROUP BY
clause. Server: Msg 8118, Level 16, State 1, Line 1
Column 'positionView.ACCT_NUMBER' is invalid in the select list because
it is not contained in an aggregate function and there is no GROUP BY
clause. Server: Msg 8118, Level 16, State 1, Line 1
Column 'positionView.FUND_ID' is invalid in the select list because it
is not contained in an aggregate function and there is no GROUP BY
clause.
I'm wondering if it's even possible to do what I'm doing wihtout
spelling out the "Position_Date Between" clause twice...
DAvid|||On Thu, 17 Feb 2005 10:59:36 -0800, DWalker wrote:

>"James Goodwin" <jim.goodwin@.midmichigan.org> wrote in news:b424$4214e40a
>$432498ca$26444@.allthenewsgroups.com:
>
>Yes, but I hate repeating clauses, and sometimes I get parentheses in the
>wrong places.
>I now have this, and it works. (Pay no attention to the Select *)
(snip)
>Question: Is there any way with table aliases to avoid repeating the
>"Position_Date Between" clause in the query? I know it might not be
>faster, but it will be simpler. I can't figure out how to do that.
Hi David,
You can't always prevent having to repeat things. But in your case, I
think it is possible. Looking at just your query, without knowing your
tables and therefore unable to test it, I think you should get the same
results from
Select Column1, Column2, ..., ColumnN from
PositionView As PositionSlice
Where Exists
(Select * From
(Select SSN_Tin, Acct_Number, Fund_ID, Max(Position_Date) as LastDate
From PositionView
Where Position_Date Between '2005-01-31' and '2005-02-03'
Group by ssn_tin, acct_number, fund_id) As LastPos
Where PositionSlice.SSN_Tin = LastPos.SSN_Tin
And PositionSlice.Acct_Number = LastPos.Acct_Number
And PositionSlice.Fund_ID = LastPos.Fund_ID
And PositionSlice.Position_Date = LastPos.LastDate)
Or even
SELECT Column1, Column2, ..., ColumnN
FROM PositionView AS PositionSlice
WHERE Position_Date =
(SELECT MAX(Position_Date)
FROM Position_View AS LastPos
WHERE LastPos.Position_Date BETWEEN '2005-01-31' AND '2005-02-03'
AND PositionSlice.SSN_Tin = LastPos.SSN_Tin
AND PositionSlice.Acct_Number = LastPos.Acct_Number
AND PositionSlice.Fund_ID = LastPos.Fund_ID)
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)|||"DWalker" <none@.none.com> wrote in message
news:#28IjwTFFHA.1392@.tk2msftngp13.phx.gbl...
> That doesn't work. See below...
> Your suggestion returns these errors:
> Server: Msg 8118, Level 16, State 1, Line 1
> Column 'positionView.SSN_TIN' is invalid in the select list because it
> is not contained in an aggregate function and there is no GROUP BY
> clause. Server: Msg 8118, Level 16, State 1, Line 1
> Column 'positionView.ACCT_NUMBER' is invalid in the select list because
> it is not contained in an aggregate function and there is no GROUP BY
> clause. Server: Msg 8118, Level 16, State 1, Line 1
> Column 'positionView.FUND_ID' is invalid in the select list because it
> is not contained in an aggregate function and there is no GROUP BY
> clause.
So add the group by clause, keep in mind, I don't have your tables and can't
test these:
Select * from PositionView p
inner join (Select SSN_Tin, Acct_number, Fund_id, Max(Position_Date)
as lastdate
From positionView where Position_date Between
'20050131' and '20050203'
Group by SSN_Tin, Acct_number, Fund_id) t
on p.SSN_Tin = l.SSN_Tin
and p.Acct_number = l.Acct_number
and p.Fund_Id = l.Fund_Id
and p.Position_Date = l.LastDate|||Thanks, I'll look at that.
David
Hugo Kornelis <hugo@.pe_NO_rFact.in_SPAM_fo> wrote in
news:agdb11tunlg45j5o3bru281vc7dpjbc0k2@.
4ax.com:

> On Thu, 17 Feb 2005 10:59:36 -0800, DWalker wrote:
>
> (snip)
> Hi David,
> You can't always prevent having to repeat things. But in your case, I
> think it is possible. Looking at just your query, without knowing your
> tables and therefore unable to test it, I think you should get the
> same results from
> Select Column1, Column2, ..., ColumnN from
> PositionView As PositionSlice
> Where Exists
> (Select * From
> (Select SSN_Tin, Acct_Number, Fund_ID, Max(Position_Date) as LastDate
> From PositionView
> Where Position_Date Between '2005-01-31' and '2005-02-03'
> Group by ssn_tin, acct_number, fund_id) As LastPos
> Where PositionSlice.SSN_Tin = LastPos.SSN_Tin
> And PositionSlice.Acct_Number = LastPos.Acct_Number
> And PositionSlice.Fund_ID = LastPos.Fund_ID
> And PositionSlice.Position_Date = LastPos.LastDate)
> Or even
> SELECT Column1, Column2, ..., ColumnN
> FROM PositionView AS PositionSlice
> WHERE Position_Date =
> (SELECT MAX(Position_Date)
> FROM Position_View AS LastPos
> WHERE LastPos.Position_Date BETWEEN '2005-01-31' AND
> '2005-02-03' AND PositionSlice.SSN_Tin = LastPos.SSN_Tin
> AND PositionSlice.Acct_Number = LastPos.Acct_Number
> AND PositionSlice.Fund_ID = LastPos.Fund_ID)
> Best, Hugo|||Thanks, I'll look at that. You have an a alias t where I think you mean
l, but otherwise it looks OK. (I don't like one-letter aliases, but
that's just my preference. Something like LastPos is more meaningful
than l. And l looks like I anyway, depending on the font. But thanks
for the help!
David Walker
"James Goodwin" <jim.goodwin@.midmichigan.org> wrote in
news:beab9$4215f005$432498ca$15926@.allth
enewsgroups.com:

> "DWalker" <none@.none.com> wrote in message
> news:#28IjwTFFHA.1392@.tk2msftngp13.phx.gbl...
> So add the group by clause, keep in mind, I don't have your tables and
> can't test these:
> Select * from PositionView p
> inner join (Select SSN_Tin, Acct_number, Fund_id,
> Max(Position_Date)
> as lastdate
> From positionView where Position_date Between
> '20050131' and '20050203'
> Group by SSN_Tin, Acct_number, Fund_id) t
> on p.SSN_Tin = l.SSN_Tin
> and p.Acct_number = l.Acct_number
> and p.Fund_Id = l.Fund_Id
> and p.Position_Date = l.LastDate
>

cant create VIEW. HELP!

ok, i've been trying this for hours now and i keep getting errors. here is my scripts for creating the VIEW in PL/SQL. if i do it with double-quotes like this:

SQL> CREATE VIEW
2 "MY_ADDSTUDENTTARGET" ("DEMOGRAPHICID","ETHNICITYID","REFERRERID","DEMOGRAPHICSTUDENTID","ACADE
MICYEARID","DOB","EMAIL","FNAME","HOMEADDRESS1","HOMEADDRESS2","HOMECITY","HOMECOUNTRY","HOMEPOST","
HOMESTATE","LNAME","MAILINGADDRESS1","MAILINGADDRESS2","MAILINGCITY","MAILINGCOUNTRY","MAILINGPOST",
"MAILINGSTATE","MNAME","PHONE1","SEX","SSN","STUDENTSTATUS","STUDENTTYPE","SUPPCOLLEGEID","CURRENTOU
","MAJORID","OUSTUDENTTYPE","VA","SUPPHSID","HOMEHS","HSADDR1","HSADDR2","HSCITY","HSSTATE","HSPOST"
,"HSPHONE","LOGINID","STUDENTACCOUNTID", "ACCOUNTID", "ACCOUNTSTUDENTID")
3 AS
4 SELECT DEMOGRAPHIC.DEMOGRAPHICID, DEMOGRAPHIC.ETHNICITYID, DEMOGRAPHIC.REFERRERID, DEMOGRAPHIC.
STUDENTID, STUDENT.ACADEMICYEARID, STUDENT.DOB, STUDENT.EMAIL, STUDENT.FNAME, STUDENT.HOMEADDRESS1,S
TUDENT.HOMEADDRESS2, STUDENT.HOMECITY, STUDENT.HOMECOUNTRY, STUDENT.HOMEPOST, STUDENT.HOMESTATE, STU
DENT.LNAME, STUDENT.MAILINGADDRESS1, STUDENT.MAILINGADDRESS2, STUDENT.MAILINGCITY, STUDENT.MAILINGCO
UNTRY, STUDENT.MAILINGPOST, STUDENT.MAILINGSTATE, STUDENT.MNAME, STUDENT.PHONE1, STUDENT.SEX, STUDEN
T.SSN, STUDENT.STUDENTSTATUS, STUDENT.STUDENTTYPE, SUPPCOLLEGE.SUPPCOLLEGEID, SUPPCOLLEGE.CURRENTOU,
SUPPCOLLEGE.MAJORID, SUPPCOLLEGE.OUSTUDENTTYPE, SUPPCOLLEGE.VA, SUPPHS.SUPPHSID, SUPPHS.HOMEHS, SUP
PHS.HSADDR1, SUPPHS.HSADDR2, SUPPHS.HSCITY, SUPPHS.HSSTATE, SUPPHS.HSPOST, SUPPHS.HSPHONE, STUDENT.L
OGINID, STUDENTACCOUNT.STUDENTACCOUNTID, STUDENTACCOUNT.ACCOUNTID, STUDENTACCOUNT.STUDENTID
5 FROM DEMOGRAPHIC, STUDENT, SUPPCOLLEGE, SUPPHS, STUDENTACCOUNT;

i get the followimg error: "MY_ADDSTUDENTTARGET" ("DEMOGRAPHICID","ETHNICITYID","REFERRERID","DEMOGRAPHICSTUDENTID","ACADEMICYE

ERROR at line 2:
ORA-00972: identifier is too long

if i do it without the quotes around the VIEW name and column names, i get this error: MICYEARID,DOB,EMAIL,FNAME,HOMEADDRESS1,HOMEADDRESS 2,HOMECITY,HOMECOUNTRY,HOMEPOST,
*
ERROR at line 3:
ORA-00907: missing right parenthesis

help, i don't know what to do.
thanks.

system: WinXP, Oracle8iEach column name has a limit of 30 characters from SQL / PLSQL.

"SESTUDENTACCOUNT.STUDENTACCOUNTID"|||well, i got rid of that really long column name (31 chars), but i am still getting the same error. any ideas?|||never mind, i figured it out. apparently, there is a command line string limit in pl/sql. you learn something new every day i guess.

Wednesday, March 7, 2012

Can't create INSTEAD OF trigger

I wanted to learn how to do this, so I created the following non-updatable
view:
CREATE VIEW [dbo].[TestAggregateView]
WITH SCHEMABINDING, VIEW_METADATA
AS
SELECT C.CustId, C.CrLmt, SUM(A.OrigDocAmt) AS TotAmt
FROM dbo.Customer AS C INNER JOIN
dbo.ARDoc AS A ON A.CustId = C.CustId
GROUP BY C.CustId, C.CrLmt
I wrote this UPDATE statement, which fails:
UPDATE TestAggregateView SET
CrLmt = 20000
WHERE CrLmt = 0
AND TotAmt > 10000
The goal is to create a trigger that will run a different and valid update
statement. Here is the code I tried:
CREATE TRIGGER [dbo].[TestAggregateView_Instead_Update]
ON [dbo].[TestAggregateView]
INSTEAD OF UPDATE
AS
BEGIN
SET NOCOUNT ON;
UPDATE Customer SET
CrLmt = 20000
WHERE Customer.CustID = inserted.CustID
END
The error I get is:
Msg 4104, Level 16, State 1, Procedure TestAggregateView_Instead_Update,
Line 14
The multi-part identifier "inserted.CustID" could not be bound.
Can someone tell me what I'm doing wrong? I could not find a sample INSTEAD
OF UPDATE trigger to compare this with, but according to the sample INSTEAD
OF INSERT, inserted is the valid name for the temporary table, and I think it
should hold all the records that meet the select requirements.Here's the problem:
UPDATE Customer SET
CrLmt = 20000
WHERE Customer.CustID = inserted.CustID
You refer to a tablme named INSERTED in the WHERE clause but you haven't listed it in the "FROM"
clause (I put FROM in quptes since UPDATE according to ANSI SQL doesn't have a FROM clause).
So the problem is with your UPDATE inside your trigger, not with the trigger per se. You have to
re-write that UPDATE so it is a valid UPDATE statement. For instance
UPDATE Customer
SET CrLmt = 20000
WHERE Customer.CustID IN (SELECT CustID FROM inserted)
Or:
UPDATE Customer
SET CrLmt = 20000
WHERE EXISTS(SELECT * FROM inserted AS i WHERE i.CustID = Customer.CustID )
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi
"Bev Kaufman" <BevKaufman@.discussions.microsoft.com> wrote in message
news:F1BAB94D-ECFE-4BF7-B1EB-1330FFD17B0F@.microsoft.com...
>I wanted to learn how to do this, so I created the following non-updatable
> view:
> CREATE VIEW [dbo].[TestAggregateView]
> WITH SCHEMABINDING, VIEW_METADATA
> AS
> SELECT C.CustId, C.CrLmt, SUM(A.OrigDocAmt) AS TotAmt
> FROM dbo.Customer AS C INNER JOIN
> dbo.ARDoc AS A ON A.CustId = C.CustId
> GROUP BY C.CustId, C.CrLmt
> I wrote this UPDATE statement, which fails:
> UPDATE TestAggregateView SET
> CrLmt = 20000
> WHERE CrLmt = 0
> AND TotAmt > 10000
> The goal is to create a trigger that will run a different and valid update
> statement. Here is the code I tried:
> CREATE TRIGGER [dbo].[TestAggregateView_Instead_Update]
> ON [dbo].[TestAggregateView]
> INSTEAD OF UPDATE
> AS
> BEGIN
> SET NOCOUNT ON;
> UPDATE Customer SET
> CrLmt = 20000
> WHERE Customer.CustID = inserted.CustID
> END
> The error I get is:
> Msg 4104, Level 16, State 1, Procedure TestAggregateView_Instead_Update,
> Line 14
> The multi-part identifier "inserted.CustID" could not be bound.
> Can someone tell me what I'm doing wrong? I could not find a sample INSTEAD
> OF UPDATE trigger to compare this with, but according to the sample INSTEAD
> OF INSERT, inserted is the valid name for the temporary table, and I think it
> should hold all the records that meet the select requirements.
>

Cant create index on view

Hi,

SQL Server 2005 (SP2) Developer edition on XP Pro

Can anyone help with setting up an indexed view? Part of the select statement calls a couple of very simple functions which are deterministic. The functions which are shown below do not perform any aggregation.

This is the error message.

Msg 8668, Level 16, State 0, Line 2
Cannot create the clustered index 'IX3_SA' on view 'XPS.dbo.SA_INDEXED' because the select list of the view contains an expression on result of aggregate function or grouping column. Consider removing expression on result of aggregate function or grouping column from select list.

Function definitions:

create FUNCTION [dbo].[MonthName](@.MonthNo TINYINT)
RETURNS CHAR(3)
with schemabinding
AS
BEGIN
DECLARE @.MonthName CHAR(3)
IF @.MonthNo BETWEEN 1 AND 12 SET @.MonthName = SUBSTRING('JanFebMarAprMayJunJulAugSepOctNovDec',((@.MonthNo*3) -2),3)
RETURN ISNULL(@.MonthName,'')
END

create FUNCTION [dbo].[FinancialYear](
@.Year INT,
@.MonthNo TINYINT,
@.YearEndMonthNo TINYINT)
RETURNS INT
with schemabinding
AS
BEGIN
DECLARE @.FinancialYear INT
IF @.MonthNo <= @.YearEndMonthNo
SET @.FinancialYear = @.Year
ELSE
SET @.FinancialYear = @.Year + 1
RETURN @.FinancialYear
END

The first part of the select statement is as follows:

(SELECT
count_big(*) as CB,

dbo.FinancialYear(YR.Number,MTH.Number,YEAR_END_MONTH) AS REPORT_FINANCIAL_YEAR,
dbo.MonthName(MTH.Number) + ' ' + CAST(YR.Number AS CHAR(4)) AS REPORT_MONTH,
dbo.MonthName(YEAR_END_MONTH) + ' ' + CAST(dbo.FinancialYear(YR.Number,MTH.Number,YEAR_END_MONTH) AS CHAR(4)) AS REPORT_FINANCIAL_YEAR_END,

I can create the index on this view if I comment out the calls to the functions so I know that is where the problem is. I can't however see why this is erroring as both only return a single value without any agregation.

Anyone got any ideas on this?

Thanks in advance

David.


Well that met with a deafening silence.

The answer was to move these function calls out of the indexed view definition into a standard view that sits above it.

Cant create an index on my view

G'day all.

I am trying to create an index on a view that joins two tables.

I get the classic error of course:
'Cannot index the view 'dbname.dbo.HJC_net'. It contains one or more disallowed constructs.'

Thing that gets me is that it all seems pretty normal stuff and I can't see what is stopping it.

Code is below and any help greatly appreciated.

CREATE VIEW dbo.HJC_net WITH SCHEMABINDING AS
SELECT t_number
FROM dbo.ticket_cancellations RIGHT OUTER JOIN
dbo.tickets ON dbo.ticket_cancellations.tc_system_ref = dbo.tickets.t_number
WHERE dbo.tickets.t_cancelled <> - 1 OR
-- Add all cancellation codes that are to be excluded from the NET view below
(dbo.ticket_cancellations.tc_cancellation_code <> 83943
AND dbo.ticket_cancellations.tc_cancellation_code <> 83946)

GO
-- Create a clustered index, it MUST be unique
CREATE UNIQUE CLUSTERED INDEX t_number_unique ON HJC_net(t_number)BOL:

The SELECT statement in the view cannot contain these Transact-SQL syntax elements:
...
Outer or self joins
...