How To Use Views In ASP.NET 2005

May 9, 2007

Hi,

   I have created some views of the select join query in sql server 2005.

   I want to make use of this views with the asp.net 2005 with C# code.

   I m using SQLDATASOURCE to retrieve data from sqlserver.

   Can anyone help me how to write in C#

VIEW SELECT CAST(LEFT(SalesReturnDate, 11) AS datetime) AS Date, SUM(TotalAmount) AS Salesreturn
FROM dbo.dfh_SalesReturnHeader
GROUP BY CAST(LEFT(SalesReturnDate, 11) AS datetime) This is the sample view how to connect it with asp.net C#,sqldatsource of 2005
Thanxs in adv.
  

View 1 Replies


ADVERTISEMENT

Are Embedded Views (Views Within Views...) Evil And If So Why?

Apr 3, 2006

Fellow database developers,I would like to draw on your experience with views. I have a databasethat includes many views. Sometimes, views contains other views, andthose views in turn may contain views. In fact, I have some views inmy database that are a product of nested views of up to 6 levels deep!The reason we did this was.1. Object-oriented in nature. Makes it easy to work with them.2. Changing an underlying view (adding new fields, removing etc),automatically the higher up views inherit this new information. Thismake maintenance very easy.3. These nested views are only ever used for the reporting side of ourapplication, not for the day-to-day database use by the application.We use Crystal Reports and Crystal is smart enough (can't believe Ijust said that about Crystal) to only pull back the fields that arebeing accessed by the report. In other words, Crystal will issue aSelect field1, field2, field3 from ReportingView Where .... eventhough "ReportingView" contains a long list of fields.Problems I can see.1. Parent views generally use "Select * From childview". This meansthat we have to execute a "sp_refreshview" command against all viewswhenever child views are altered.2. Parent views return a lot of information that isn't necessarilyused.3. Makes it harder to track down exactly where the information iscoming from. You have to drill right through to the child view to seethe raw table joins etc.Does anyone have any comments on this database design? I would love tohear your opinions and tales from the trenches.Best regards,Rod.

View 15 Replies View Related

Views Problem In SQL 2005

Jan 17, 2008

So, my SQL server was recently upgraded from SQL 2000 to SQL 2005. Everything seemed to go smoothly and look good, but now it seems that a view that had been created in SQL2000 isn't working as it should, and I can't for the life of me figure out why.
Here's the deal - I have a phone/email directory page & database that I maintain, and this view is supposed to pull data from 2 different tables and combine it into one view - specifically matching people with their associated organizations (and pulling the needed data on each organization), and then this should be sorted first by the OrgID, and then by the PersonID. The OrgID sort is working just fine, but for some reason it's not necessarily then sorting by PersonID anymore. I tried creating a whole new view using the designer in SQL Server Management Studio, but it has the same problem.
I'm including the queries for each of the views below - any help would be much appreciated!
Thanks
Kaiti
Original View:USE [DirectorySQL]GO/****** Object:  View [dbo].[OrgView]    Script Date: 01/17/2008 12:07:56 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOALTER VIEW [dbo].[OrgView]ASSELECT     TOP 100 PERCENT *FROM         dbo.OrgList INNER JOIN                      dbo.Merge ON dbo.OrgList.OrgID = dbo.Merge.MergeOrgIDORDER BY dbo.OrgList.OrgName, dbo.Merge.MergePersonID
New View:USE [DirectorySQL]GO/****** Object:  View [dbo].[NewOrgView]    Script Date: 01/17/2008 12:08:14 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOALTER VIEW [dbo].[NewOrgView]ASSELECT     TOP (100) PERCENT dbo.Merge.MergePersonID, dbo.Merge.MergeOrgID, dbo.Merge.MergeTitle, dbo.OrgList.OrgID, dbo.OrgList.OrgName,                       dbo.OrgList.OrgType, dbo.OrgList.OrgAssociation, dbo.OrgList.OrgOffice, dbo.OrgList.OrgCampusMail, dbo.OrgList.OrgFax, dbo.OrgList.OrgInfoPhone,                       dbo.OrgList.OrgInfoEmailFROM         dbo.Merge INNER JOIN                      dbo.OrgList ON dbo.Merge.MergeOrgID = dbo.OrgList.OrgIDORDER BY dbo.OrgList.OrgID, dbo.Merge.MergePersonID

View 6 Replies View Related

Creating Views In SQL 2005

Jun 17, 2008

can anyone tell me why when I create a view if I do this in my select statement "CAST(CrewNo AS char(10)) AS CrewNo" and then save the view the above CAST statement will be changed to this "CAST(CrewNo AS char(10)) AS Expr1". After I have it saved and then go back and change it back to "CAST(CrewNo AS char(10)) AS CrewNo" it will stay that way. Just looking for a reason why this is happening as I don't know if I'm doing something wrong or not.

View 2 Replies View Related

SQL 2005: ISNUMERIC() And Views

Sep 10, 2007

Hello all!

I've wrote a small query for SQL 2005 and it's doesn't seem to work.

I have a table that contains two columns (X and Y), X is an int and Y is an nvarchar(50). I've populated this table with some data where Y contains numbers and some strings (e.g. "1", "2", "foo", etc). I've then got a view which only returns the rows where Y is numeric - now, I then query this table stating I only want numbers greater than 0 (i've casted the column) but this throws an error stating "foo" can't be casted. This is strange because the view doesn't return that.

What's going on? All of this works fine in SQL 2000 but not in SQL 2005 - looks like it's looking at the underlying table rather than the view. Sample code below to help you all out: -

Create Table
============
CREATE TABLE [dbo].[tblTest](
[X] [int] NOT NULL,
[nvarchar](50) NOT NULL
) ON [PRIMARY]


Insert Data
===========
INSERT INTO tblTest(X, Y) VALUES(1, '1')
INSERT INTO tblTest(X, Y) VALUES(1, '2')
INSERT INTO tblTest(X, Y) VALUES(2, 'foo')
INSERT INTO tblTest(X, Y) VALUES(2, 'bar')


Create View
===========
CREATE VIEW [dbo].[vwTest]
AS
SELECT X, Y
FROM dbo.tblTest
WHERE (ISNUMERIC(Y) = 1)


Finally
=======
SELECT X, Y
FROM dbo.vwTest
WHERE (CONVERT(int, Y) >= 0)

Msg 245, Level 16, State 1, Line 1
Conversion failed when converting the nvarchar value 'foo' to data type int.




Thanks in advance!

View 10 Replies View Related

SQL Server 2005 Replication And Views

Feb 24, 2006

Hi,

I read that views can't be published with SQL Server 2005 replication. Is this planned for the future? If not what alternatives are there for this?

Simple collecting the data needed in a new table ain't a solution for us (memory consuming). And joining the data on the PPC ain't a good solution either (memory and time consuming). We only want to pull the data.

Greets,

Ivo Klerkx

View 3 Replies View Related

2005 Replication With SCHEMABINDING Subscriber Views

Dec 6, 2007

Hi Folks Is there an easy way around this ? One Way Transactional Rep Subscriber needs SCHEMABINDING on the majority of their Views (require View Indexes) which read from Replicated Tables. Main table has 4 Million Rows ReInitialize Subscription Errors with Cannot Drop Table because it is being referenced By Object ..... [schemaBound View] GW

View 6 Replies View Related

Sql Server 2005 Questions Regarding Editing Views

Jun 21, 2006

Previously in Sql Server 2000, we would be in enterprise manager, you'ddouble click on a view, and a nice little dialog box opened with the t-sqlstatetments, there was also a check sql syntax and apply and cancel buttons.Not exactly query anaylizer, just a quick lightweight dialog box. Is thisfeature still around? Seems like I have to go into the query anaylizer likemode to edit a view now. I am a total newbie to version 2005. Are there anyoptions I can set to make it behave the old way? All feedback isappreciated.TIA,~CK

View 2 Replies View Related

SQL Svr 2005 - Use Same Stored Proc && Views For 2 Databases?

Jan 10, 2007

I am moving a fairly large app from Access 2003 to C#/SQL Server 2005.

The app has one front end mde, but it has two backend data mdbs, one is used in the US and one in the UK.

The two backend mdb's are identical in structure, but of course the data is different. There are 150 tables or so, and we plan to maintain separate databases after the upgrade.

Now, of course, all of the queries are in the front end, the backend db's contain only tables.

In the new world, I do not want to have to maintain the same views and stored procs in two different SQL Server databases.

Is there a way to have all views and stored procs in one database, but have them draw on the data in the two other databases. There must should be a way to deal with this scenario in SQL Server.

Many thanks
Mike Thomas

View 5 Replies View Related

Get The List Of Catalog Views In SQL Server 2005

Oct 10, 2006

How to get the list of catalog views sys.* (sys.objects, sys.columns ....) in sql server 2005

select * from sys.objects where objectproperty(object_id, 'IsSystemTable') = 1

did not return the list as I've expected

thanks

View 4 Replies View Related

Does Sql Server 2005 Compact 3.5 Support Views?

Feb 29, 2008

I think I read somewhere that sql server 2005 Compact Edition (3.1) does not support views. Does anyone know if views were added to 3.5?

View 3 Replies View Related

SQL 2005 Breaks Writeable Multi-table Views

Sep 25, 2006

Hi,

I have some simple views that bind to an Access forms for use in the detail side of Master/Detail forms.

The views are of the style:

SELECT *.OrderDetails, Products.TotalUnitsInStock AS UsefulReferenceInfo

FROM OrderDetails LEFT OUTER JOIN Products ON ..........

Using a database in SQL 2000, opening the view to directly insert values into the OrderDetails columns works perfectly, and Access correctly determines that there is an IDENTITY column that is the Primary Key. Insert works perfectly, form work perfectly.

Using the same SQL script to build a database in SQL 2005 the view doesn't detect that the column is an IDENTITY column so any attempt to insert data fails with the error "Invalid input parameter values. Check the status values for detail." Insert fails, form also doesn't work.



I have tested this in Access 2002, 2003 and 2007 B2TR and all give the same results so it seems to be a breaking change in SQL 2005.

It is easy to see when there is going to be trouble because the tell-tale '(Auto Number)' or more recently '(New)' text is missing from the appropriate identity column.

This is fairly inconvenient and breaks quite a lot of my Master/detail forms that use this design pattern.

Can anybody from the SQL team help shed some light on this for my.

Cheers Simon

View 11 Replies View Related

Large Views Vs Multiple Small Views

Sep 6, 2007

Which is more efficient? One large view that joins >=10 tables, or a few smaller views that join only the tables needed for individual pages?

View 1 Replies View Related

Strange Exceptions With Views Usings Casts On 2005 (worked Fine On Sql2k)

Apr 3, 2007

I have views that cast the data into data types.



On 2005 when retrieving the views using a where clause i get errors. I have put together an example below that illustrates the error.



CREATE TABLE TestData ( Id VARCHAR(10), [Description] VARCHAR(20), [Type] INT)

CREATE TABLE TestTypeLookup( [Type] INT, [Description] VARCHAR(20))

GO

INSERT INTO TestTypeLookup VALUES (1, 'Type 1')

INSERT INTO TestTypeLookup VALUES (2, 'Type 2')

INSERT INTO TestData VALUES ('AA', 'Description for AA', 1)

INSERT INTO TestData VALUES ('10', 'Description for 10', 2)

INSERT INTO TestData VALUES ('20', 'Description for 20', 2)

GO

CREATE VIEW TestView AS

SELECT TOP 100 PERCENT CAST(Id AS INT) Id, [Description]

FROM TestData

WHERE [Type] = (SELECT TOP 1 [Type] FROM TestTypeLookup WHERE [Description] = 'Type 2')

ORDER BY CAST(Id AS INT)

GO

SELECT * FROM TestView WHERE Id = 10

GO

DROP VIEW TestView

DROP TABLE TestData

DROP TABLE TestTypeLookup

GO

View 11 Replies View Related

Distributed Query From SS 2000 To Access Catalog Views On SS 2005 Via Linked Server

Aug 24, 2006

I am trying to write some admin only procedures which will collect information to one of my development server from other production and development servers.
 
I have created linked servers to access these other servers on the development server. This development server is SQL Server 2000 EE. Other servers which I want to access are 2000 and 2005 (vaious editions)
 
E.g I have another development server called PRODTEST which is SQL Server 2005 and on the development server I have created a linked server pointing to PRODTEST called TESTLINKSRV. I want to access new object catalog view (as I do not want to use sysobjects)
 
When I run the following query
 
SELECT * FROM [TESTLINKSRV].[DBNAME].[sys].[objects]
 
I get following error,
 
OLE DB error trace [Non-interface error:  OLE DB provider does not contain the table: ProviderName=' TESTLINKSRV ', TableName='" DBNAME "."sys"."objects"'].
 
Msg 7314, Level 16, State 1, Line 1
 
OLE DB provider ' TESTLINKSRV ' does not contain table '"DBNAME"."sys"."objects"'.  The table either does not exist or the current user does not have permissions on that table.
 
So I try this query
 
SELECT * FROM [TESTLINKSRV].[DBNAME].[sys.objects]
 
and I get following error
 
Msg 208, Level 16, State 1, Line 1
 
Invalid object name TESTLINKSRV.DBNAME.sys.objects'.
 
So bottom line is how do I access catalog views on a 2005 server from a 2000 server using linked server?
 
I hope someone understands what I am trying to achieve. Please let me know what is it that I am doing wrong.
Thank you

View 5 Replies View Related

Recompiling Views That Reference Other Views

Jun 28, 2007

Hello.

Newbie here. I've only been using SQL for about a year now and have some minor questions about sql objects that reference other objects.



We have some views which reference other views in the joins. I will call one the primary view and the one being referenced in the joins as the secondary view.

Recently we made changes to the secondary view.

After which the primary views which referenced it would not work because of this change and had to be 'refreshed' by using drop/create scripts which essentially just dropped it and recreated the exact same view. I do not recall the exact error message that was returned other than it seemed to suggest that it could no longer see the secondary view since it had been changed. Nothing in the primary view was changed in any way, just the secondary.



Some here where I work have suggested off hand that this was a recompile of the primary view because the contents of the secondary changed.

My questions are:

1. Exactly why did this happen and is there a proper name for it when it does?

2. The same problem does not seem to occur when we have stored procedures referencing views in the joins which had just been changed. Why is that?



Thanks for any help on the matter. I greatly appreciate it.

View 3 Replies View Related

Quicky : Views Of Views Of Views

Feb 22, 2007

Hello,

to make a report easier I'm developing it using a view of joined views of joined views.

Is there any significant performance penalty as opposed to just having one big select?

Cheers.

View 1 Replies View Related

Views Dependent On Other Views

Mar 14, 2006

Hello There,I'm trying to create a view that has calculations dependent oncalculations, where the problem resides is that each time I make acalculation I must create an intermediate view so I can reference aprevious calculation.for example lets say I have my_table that has columns a & b. now I wanta view that has a & b, c = a + b, and d = c + 1.this is grossly simplified, the calculations I actually use are fairlycomplex and copying / pasting them is out of the question.so what I have is my_view_a which makes column c, and my my_view_finalwhich makes column d (however, in my real application I have 5 of theseviews, a/b/c/d/e/)is there anyway I can consolidate all these views into one? I wasthinking of using a stored procedure with temp tables or somethingalong those lines.I just which I can use the aliases that I create for c in d in onestep.any insight would be greatly appreciated.

View 5 Replies View Related

Can Some One Help Me With SQL VIEWS

Apr 15, 2008

Hi everyone,                    I have a problem like this . I have tables Coursegroupcode, which has groupname, codeI have Courses That has Coursename, its code(group code),Term, Course Number Enrollment table which has Foreign keys Term,Course NUmber , SSN     I need to get a view like thisI should list all the coursecodes and people enrolled for each course code for selected terms  Course Table Primary keys(TERM,COUSE Number)Enrollment Table(Foreign keys) TERM ,COURSE NUMBER, SSNplease help 

View 9 Replies View Related

Sql Views

Apr 7, 2005

 Hi!
I need to know if i can build an aspx file on top of an sql view? I
can only see my tables when i connect to the database....
Collette.

View 3 Replies View Related

SQL Views

Oct 18, 2005

Can SQL Views insert to the tables they are created from?I have a database that is not well structured. It has a lot of redundency. What I want to do is create a SQL View that brings in all the data I need and have my application use that new SQL View instead of the data tables. Then I want to be able to insert new information to a SQL View that actualy gets inserted into the tables that the SQL Viewer is created from.Can this be done?Does this make any sense?

View 1 Replies View Related

Views

Mar 26, 2001

I have a query which unions the four select statements.....

the select statements are joined with other tables and views.....


When i execute the query i get ODBC timeout error........

But the strange thing is that if i execute the view individually once and again execute the query it works fine.......and later it justs works fine....

Can anyone tell why is it like that.......

Thanks,
Sajai.

View 1 Replies View Related

SP's And Views

May 23, 2000

Is there a performance hit running a sp against a view versus a base table. The view just excludes
several of the records based on some criteria, and all the data I will be retreiving is included in
the view. Or should I just stick my criteria in the SP to exclude the data?

View 1 Replies View Related

Iif Views

Jun 19, 2000

Is there a way to imbed "iif"-like logic in a SQL view? "case when" works in regular queries, but apparently is not supported in views...

View 1 Replies View Related

Views

Aug 14, 2002

I have some rather complex views to work with. Do they slow you down? Would it be better to move a view into a stored procedure? Is there any difference between these three solutions?
<B>1.Using views:</b>
Create view X
As
Select Col1, Col2, Col3 from Table1
Go

Create view Y
As
Select Col1, Col2, Col3 from Table2
Go

Create proc Z
As
Select X.Col2, X.Col3, Y.Col2, Y.Col3
From X inner join Y on X.Col1 = X.Col1
GO

<b>2.Using just a stored proc:</b>
Create proc Z
As
Select X.Col2, X.Col3, Y.Col2, Y.Col3
from
(Select Col1, Col2, Col3 from Table1) X inner join
(Select Col1, Col2, Col3 from Table2) Y on X.Col1 = Y.Col1

<b>.Joining tables</b>
Create proc Z
As
Select Table1.Col2, Table1.Col3, Table2.Col1, Table2.Col3
FromTable1 inner join Table2 on Table1.Col1 = Table2.Col1
go

Thank you!

View 1 Replies View Related

VIEWS

Aug 1, 2001

I am struggling with setting up views in SQL Server 7.0 and 2000. What types of views are available.

I have one database with 112 tables and 2308 fields.

Thanks in Advance

View 1 Replies View Related

Views

Jun 9, 2004

I have created a database connected to a GUI using VB 6.0. When editing the views from the front end, do the tables also get updated


Thanks

View 3 Replies View Related

Views ?

Aug 17, 2004

Hi,

Is there a way to create a view with read only option. i.e the view should not allow the user to perform insert, update or delete action on it.

Please advise,

Thanks,
Sam

View 1 Replies View Related

MS SQL Views

Dec 23, 2004

Is there any kind of lock on a view in ms sql database?

what happens if one of my users is looking at the view and another one is adding something to the database?

Thanks.

View 3 Replies View Related

SQL Views

Sep 26, 2005

My First time building "Views" in SQL...... I'm trying to figure out how to return a 1 instead of a two when I Count the number of records that return inn my view.

here's what I have;

SELECT TOP 100 PERCENT dbo.tbl_ProcTimesheet.idCalendar, dbo.tbl_ProcTimesheet.erNum, dbo.tbl_ProcTimesheet.PayDate,
COUNT(dbo.tbl_ProcTimesheet.TransAmt) AS Shifts, dbo.tbl_ProcTimesheet.[Employee Number], dbo.tbl_ProcTimesheet.YCode,
dbo.tbl_ProcTimesheet.XCode, dbo.tbl_ProcTimesheet.ZCode, dbo.tbl_ProcTimesheet.eeLink
FROM dbo.tbl_ProcTimesheet INNER JOIN
dbo.tbl_SysVarRestEeShiftPayCodes ON dbo.tbl_ProcTimesheet.Code = dbo.tbl_SysVarRestEeShiftPayCodes.PayCode INNER JOIN
dbo.tbl_SysVarRestEeShiftRules ON dbo.tbl_ProcTimesheet.YCode = dbo.tbl_SysVarRestEeShiftRules.YCode AND
dbo.tbl_ProcTimesheet.ZCode = dbo.tbl_SysVarRestEeShiftRules.ZCode
WHERE (dbo.tbl_ProcTimesheet.Sequence <> N'0') AND (dbo.tbl_ProcTimesheet.Week < 3)
GROUP BY dbo.tbl_ProcTimesheet.idCalendar, dbo.tbl_ProcTimesheet.erNum, dbo.tbl_ProcTimesheet.PayDate, dbo.tbl_ProcTimesheet.TransAmt,
dbo.tbl_SysVarRestEeShiftRules.DailyHours, dbo.tbl_ProcTimesheet.[Employee Number], dbo.tbl_ProcTimesheet.XCode,
dbo.tbl_ProcTimesheet.YCode, dbo.tbl_ProcTimesheet.ZCode, dbo.tbl_ProcTimesheet.eeLink, dbo.tbl_ProcTimesheet.Sequence,
dbo.tbl_ProcTimesheet.Week
HAVING ('IIf' > '1,1,0') AND ('if' > '1,1') AND (dbo.tbl_ProcTimesheet.erNum LIKE N'5648 ') AND (SUM(dbo.tbl_ProcTimesheet.TransAmt)
>= dbo.tbl_SysVarRestEeShiftRules.DailyHours) AND (dbo.tbl_ProcTimesheet.PayDate = CONVERT(DATETIME, '2005-09-06 00:00:00', 102)) AND
(COUNT(dbo.tbl_ProcTimesheet.TransAmt) > 0)
ORDER BY dbo.tbl_ProcTimesheet.PayDate, dbo.tbl_ProcTimesheet.[Employee Number]

When it counts shifts, I only want to return a maximum of i, as in either you had a shoft that day, or not. I gave up trying to figure out the "IF" string in SQL, and for the life of me I can not figure this out.

Does anyone know a good site with info on how to construct an SQL View?

View 12 Replies View Related

Views

Jun 1, 2004

Hi,

I'm creating a stored procedure that will Drop all views when executed, this is what i have...

DECLARE crsViews CURSOR FOR
SELECT
name AS strViews
FROM

__________ <what do i put here?

WHERE
type ='U'
AND NAME LIKE'V%'


Thanks for any help!

View 2 Replies View Related

Views

Apr 21, 2008

MS SQL Server 2005
What happens if 2 or more users use the same View at the same time or while other user is using it, normally from Crystal Reports 10
It rebuilds again? Or?

Thanks

View 2 Replies View Related

Views On Views

Apr 25, 2008

Hi,

I have a SQL server: SQL2005
2 databases
db_repl: contains replicated data from mainframe
db_my: my database

db_my.vwRepl_WorkOrders: Select 1,2,3 from db_repl.dbo.WorkOrders
db_my.vwWorkOrdersOpen: select 1,2,3 from db_my.vwRepl_WorkOrders where Status=1

which approach is more optimal to do in order to find open work orders from Texas:
[select 1,2,3
from db_repl.dbo.workOrders where Status=1 and State=1
or
select 1,2,3
from db_my.vwWorkOrdersOpenwhere where State=1]
Is it best practice to use 'subviews' that acess db_repl directly or acess views in my_db that acess db_repl (2 hops or more if views call other views that call other views) Answer might be the obvious but just in case I am missing something here .
Thanks!

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved