I have a table, the table contains a data of a Site and a monitor which monitors a site, A monitor picks certain sites quarterly to do monitoring, for instance monitor k picks site1, site2, site3 to do monitoring in the first quarter of the year 2008 then for the second quarter he picks some new sites say site4 and site5 and can also pick some site which he monitored in the previous quarters asy site1.
My problem is I want to get how many new sites did the monitor do monitoring for that quarter.
for example monitor monitored site s1, s2, s3 in 1Q2008 and site s3, s4 in 2Q2008
the count shoul look like
1Q2008 3 2Q2008 1
because he monitored 3 new sites in 1Q2008, but in 2Q2008 he picked one new and one already reviewed site s3 we only count the new ones
hope I didn't confuse you
here is the table structure
create table #siteMonitor (monitor varchar(100), quarter varchar(100), site varchar(100))
insert into #siteMonitor (monitor, quarter, site) select '1Q 2005', 'john moyes', 's0001' union all select '1Q 2005', 'john moyes', 's0002' union all select '1Q 2005', 'john moyes', 's0003' union all select '1Q 2005', 'john moyes', 's0004' union all select '2Q 2005', 'john moyes', 's005' union all select '2Q 2005', 'john moyes', 's003' union all select '2Q 2005', 'john moyes', 's006' union all select '1Q 2006', 'lori kumar', 's0007' union all select '1Q 2006', 'lori kumar', 's0008' union all select '1Q 2006', 'lori kumar', 's0009' union all select '1Q 2007', 'lori kumar', 's007' union all select '1Q 2007', 'lori kumar', 's0010' union all select '1Q 2007', 'lori kumar', 's0011' union all select '2Q 2007', 'lori kumar', 's007' union all select '2Q 2007', 'lori kumar', 's0012'
The record set should look like
monitor quarter count
john moyares 1Q 2005 4 john moyares 2Q 2005 2 lori kumar 1Q 2006 3 lori kumar 1Q 2007 2 lori kumar 2Q 2007 1
I'm developing a website using the new authentication system from asp.net 2.0 and when I try to copy the database to my server and I try to add data to it, it gives me a read-only error. I've tried several ways, but I can't seem to find the solution. It works well in my computer but if I move it to the server it just doesn't work.
Is there anything I need to do? I have all the permissions needed in IIS.
Hi, I have a SSIS package runnig trough my sql server 2005 schedule job every one hr. it is a simple package to pull some data from a table and transfer this data into a text file. it was runnign smoothly since long time, but today its not executing through my job and giving me the following error.
Executed as user: GYRODATAGyroDBA. ...n 9.00.3042.00 for 32-bit Copyright (C) Microsoft Corp 1984-2005. All rights reserved. Started: 1:13:27 PM Error: 2008-04-10 13:13:28.18 Code: 0xC001401E Source: Package1 Connection manager "DestinationConnectionFlatFile" Description: The file name "\Gyrow2kefw001PURCHASESPOOLsupplier.txt" specified in the connection was not valid. End Error Error: 2008-04-10 13:13:28.18 Code: 0xC001401D Source: Package1 Description: Connection "DestinationConnectionFlatFile" failed validation. End Error Progress: 2008-04-10 13:13:28.20 Source: Data Flow Task Validating: 0% complete End Progress Progress: 2008-04-10 13:13:28.34 Source: Data Flow Task Validating: 50% complete End Progress Progress: 2008-04-10 13:13:28.34 Source: Data Flow Task Validating: 100% complete End Progress DTExec: The package execution returned DTSER_FAILURE (1). Started: 1:13:27 PM Finis... The package execution fa... The step failed.
If i try to execute the same package trough business development studio its working f9. anyone have any idea whats the problem is? masroor
I have 2 identical tables one contains current settings, the other contains all historical settings.I could create a union view to display the current values from table A and all historical values from table B, butthat would also require a Variable to hold the tblid for both select statements.
Q. Can this be done with one joined or conditional select statement?
DECLARE @tblid int = 501 SELECT 1,2,3,4,'CurrentSetting' FROM TableA ta WHERE tblid = @tblid UNION SELECT 1,2,3,4,'PreviosSetting' FROM Tableb tb WHERE tblid = @tblid
there is a table - TableA in my DB which iam using in a stored procedure now the table is normalised and the same date is spread in 6 diff tables. my admin is creating a View which is just like TableA.
my question is do i have to change anything in my stored procedure as TableA is a view and not a table anymore.
HiComplete newbie to sql server. I have a Companies table from which I wouldlike to create a Clients view as follows;SELECT ID, Company, CompanyTypeFROM dbo.CompaniesWHERE (CompanyType = N'Client')Such that when I insert a record into this view it automatically setsCompany Type to Client. Just so I can treat the view as just another tablewithout having to worry about setting the correct company type. Is there away to do this either via views or some other way?ThanksRegards
If anyone can help... I have a function that takes one parameter andbring back quite a lot of records. but with a conventional function thefield size has a limit of 8000 and i can not use field type 'text'. thelimit has been reached and the view does not bring back results. anoption i found was to use a table function. but with my limitedexperience with table udf's, I am failing to use it within a view. I ampassing a value from the view as a parameter to use in the function andit doesnt work.Please help.*** Sent via Developersdex http://www.developersdex.com ***
I am in a scenario where my tables are refreshed every morning by a batch update. I have built a few views off of one table. To increase speed I would like to take all the rows from one of the view s and insert them into their own table. I know this can be done with some T-SQL but I'm a noob to it and don't know how to specifically do it.Any detailed help would be greatly appreciated. -Nate
I'm designing a database for my final year project at University, and have run into a bit of a dilemma with one of the tables. Basically, it's an equipment loan database where both students and lecturers need to be able to book and borrow equipment. To avoid having two separate bookings tables (i.e. StudentBookings and LecturerBookings) I've got students and lecturers combined into one table called 'Borrowers'. The trouble comes because the clients want the lecturer storing in the booking information table, which can get quite messy because lecturer information is stored in the same table as borrower information meaning that I basically need to relate both the Booking.BorrowerID and Booking.LecturerID to Borrowers.BorrowerID.
In theory, I think this could be solved by creating a View called Lecturers that pulls the required information for Lecturers out of the Borrowers table and then link Booking.LecturerID to the ID of the view. In practice, I've got a couple of queries:
1) Is it possible to perform a JOIN on a view in the way that I would need to here?
2) To keep things nice and clear, is it possible to 'rename' the BorrowerID to LecturerID whilst creating the View?
Sorry if some of this isn't too clear. Please ask any questions to clarify what I mean if you need to.
Normally i can use Web Matrix to connect to a SQL table. e.g. Dim queryString As String = "SELECT [MyTable].* FROM [MyTable]"Is is possible to connect to a SQL View. The reason is because i have generated a view using UNIONS and JOINS and some columns are generated by concatenating columns together (ie.. has alias columns).I also need to use VB.NET to refer to these alias columns.
We have a table created by an application, and a view that joins the table with other tables.
For some reason we are now unable to drop the table or the view. In Enterprise Manager the drop table dialog comes up, we click 'Drop All' and then the hour glass comes up and never goes away. No errors are returned, the process just never returns control to the client, the same when trying to remove the view. Using Query Analyzer is no different.
However stopping and starting the server resolves the problem for a while, but eventually the same problem starts happening. The table is created, populated and dropped using stored procedures called from a web page via asp script. This process may occur numerous times and hasn't been a problem until the last day or so when the developer added a couple of smallint columns to the table.
Hi all, What's different from SELECT FROM A TABLE to SELECT FROM A VIEW? Which is faster? Can anyone explain my result following? Example for: -- TABLE: set statistics io on select * from TABLE_NAME -->Table 'TABLE_NAME'. Scan count 2, logical reads 106, physical reads 0, read-ahead reads 0
-- VIEW: Create view VIEW_NAME as SELECT * FROM TABLE_NAME set statistics io on select * from VIEW_NAME -->Table 'TABLE_NAME'. Scan count 1, logical reads 53, physical reads 0, read-ahead reads 0.
Can anyone help me with displaying several table properites at once. I know I can use sp_help 'tablename' to get one at time. What is the best method to get several databases at a time?
I am working on a program for the Pocket PC platform, which will piggy-back on a helpdesk program which stores it data in an SQL server. I have no problems with getting information from the server, or any connectivity issues.
I have found that it is easy to synchronize an access .mdb file, or an ODBC Source to a .cdb file on the PPC. I have a data provider for the SQL database in question, and the "Import Database" function works fine; it pulls up a listing of all the tables and fields in the helpdesk database.
My problem is as follows. The table used to store the memo information is at least 20-30 megs. I only need a few key entries from that table. I also need to make the sync process as simple as possible (that's why i was looking into activesync), but there does not appear to be ANY way to import an SQL View, as opposed to a table.
SQL CE appears to be one possible solution, but we are running SQL 7, and the CE server tools require SQL 2000.
So, is there a way to trick activesync into sync'ing a VIEW instead of a table?
Do you have ANY OTHER ideas, which would be simple come time to sync?
I have a table that has thousands of rows inserted daily (rows are seldom updated or deleted)
The table is also involved in frequent non-simple select statements. It currently has about a million rows.
Out of the 15 odd columns in the table, I can see about 6 that would benefit being indexed to speed up the select statements.
Before I do this, I was wondering if people think that perhaps I should create an indexed view that all select statements use, rather than adding indexes directly to the table.
Can anyone advise me the performance benefits/disadvantages of indexed views over indexed tables?
Have a table with Data and Dependencies(Foreign Keys) and Stored Procedures, views etc. Need the Data in that table to put in different order. For exampl, put older years in the begining or end so when sorted by year, you will get right data. Question is: If i use view it will be based on the table with Wrong entry order and if i use Temporary Table each time stored procedure is run, it will be created and overhead.
Example of the table is below with Wrong order. I should have entered the old years first. Note this is example and not the actual table!
If this example is not right, my bottom line is this: I have entered the Data in a table and i'm getting wrong resutls when i order by Desc or Asc and now either have to delete all rows and re-enter it or have someother clever way!
I am trying to create a view using to three queries below and I get the error message Views or functions are not allowed on temporary tables. Is there a way to do that or is there a way to combine the three queries below so I don't have to use a temp table so I create a view?
--Query 1
SELECT * INTO #MOVEMENTS FROM [GW_DW].[dbo].[DimStatusHistory] d WHERE TransferFromToProgram<>'' AND d.Status=12 ;
I want to create a view from table j25_teamlist2014 with the 7 columns shown below. But I only want the rows which don't have a Status of 'Not Available'.This sql works fine apart from the Team Name and Team Captain columns display the team which is an interger ie Row 1 shows 1 in the Team Name and Team Captain columns instead of 'My Team' and 'Jo Bloggs'.Also when viewing the original table and the new view the structures are slightly different.
CREATE VIEW j25_availableteamlist2014 AS SELECT Team, Day, Time, Lane, Team Name, Team Captain, Status FROM j25_teamlist2014 WHERE Status NOT LIKE 'N%'
MVP's and the likeI am looking for suggestions , confirmationLet me start by saying bar none, performance is paramount with thequeries to be retured off this view/table query.To that end I am completley donormailzing the data into a view (or atable) with all possible legal combinations ( I have seen this refferedto as Croation Method ?) Its ends up at 3 total rows per account onaverage.THis query is to be executed only from the web, so once again theperformance is paramount.Ok here is what I have so far I have a set of related tables 5 or sothat are for the most part 1 to 1 but in the case of one particulartable its an average raqtion of 20 to 1.Broken all out with 150k customer rows it ends up at 500k total rows inthe viewAbout 7 cols are dynamic aggregates (Sum(tran_AMT)) , min(tran_amt) ,etcI had it in a view and with 1/5 million rows (In the view) it performedadequatley, I will most likeley get to somewhere around 10 milliontotal rows (In the view)I looked into indexing it but thats not going to happen because I amdoing several subquery's , outer joins etc.The View with a Select * returns in 40 SecondsNow i ran into an issue with recursing this query into several seperatesubqueries and hit the 256 table limit, after only about 15 recursions.Now the data only gets updated once , perhaps twice a day, in a batchtransaction.So I Put all the data from the view into a table, and indexed that, Ican return all rows in 12 seconds and any refining conditions I throwat it, like Date > 12/1/2003 (then it executes in under 6 second_ onlyslices the query time down big time (A very good thing)Since its only updates 2x a day I drop and recreate the table in my DTS, and I have triggers on the other tables for Online updates (usuallyno more that 100 a day) but to ensure the table is ALWAYS current itgets recreated on import of additional rows.Is there a name to this maddness ? My co-workers aree leary of it butthey come from a dbase background, denomailzing it into a table andthen indexing the table I couldnt be happeier with ther performance.Are there any lurking gremlins in this design ?I cannot see any pitfalls with doing this , or are there some ?,basically I am denomailizing for read-only query performance.They are concerned about the denorilization for performance, eventhough its only on a read only table (was and could be a view I justcant index this particualr view)So I guess Im looking for a , "Sounds OK" or "Sounds Great" from theSQL Gods ....Chris
I have a list of users that I want to restrict access to tables in a database. The goal is to allow the users to use select statements on the views instead of the tables. How can this be accomplished?
Actually I have very big size of databse. Also its back up is obvious that also biger size.
In case of only data loss of one table or view or sp or change then restore whole database then get back previous backup database & restore table i.e. it consuming too much time.
I want to restore only one table or view in faster way. how i can do it. plz give any suggestions
I am trying to create a set of "Reporting" views and grant Select permission on those views instead of the tables. I created the view in the same database but under a different schema from the tables. When the user tries to select from the views they get an error saying they do not have select privilege on the tables. Do I need to grant them select on the underlying tables?
I would like to replicate a single view to a table that is stored on another db server (connected as linked server object). Is there a way to imitate the behavior of a trigger (insert, delete, update) for a view? I could assign the triggers to the table that provides the primary key. So I could handle insert, delete events. But what about updates that affect row in other tables that are used in this view?
Code Snippet CREATE TRIGGER mirror_tableA_insert ON [TESTDB].[dbo].[tableA] FOR INSERT AS BEGIN set nocount on SET XACT_ABORT ON set REMOTE_PROC_TRANSACTIONS off INSERT INTO OPENQUERY(TESTLINKED, 'SELECT * FROM tableA') SELECT * FROM [TESTDB].[dbo].[myView] orig INNER JOIN inserted i ON i.prim = orig.prim END