I have the following query that produces this: 1 0 Arts & Entertainment6 1 Arts & EntertainmentDance2 1 Arts & EntertainmentMovies9 0 Automotive10 0 Business11 0 Cancer12 0 Communications3 0 Computers13 3 ComputersE-Learning4 3 ComputersHardware14 3 ComputersJava16 3 ComputersLink Popularity17 3 ComputersMicrosoft.net15 3 ComputersRSS5 3 ComputersSoftware7 0 Real Estate8 7 Real EstateFinance Here is the query: SELECT tblArticleCategory.ACategoryID, tblArticleCategory.AParentID, ISNULL(Parent.ParentCategory + '', '') + ISNULL(tblArticleCategory.ACategoryname, '') AS ACategory FROM tblArticleCategory FULL OUTER JOIN(SELECT ACategoryName AS ParentCategory, ACategoryID FROM tblArticleCategory AS tblArticleCategory_1 WHERE (AParentID =0) AND (AActive = 1)) AS Parent ON Parent.ACategoryID = tblArticleCategory.AParentID WHERE (tblArticleCategory.AActive = 1) ORDER BY ACategory How do I modify this so that just the category name is returned and not the parent cetegory. In other words, everything shows up just once. Arts and Entertainment, once, then on the next line Dance, then Music then the next parent category which is automotive. Here is the table: ACategoryID int UncheckedACategoryName nvarchar(150) CheckedADescription nvarchar(300) CheckedAParentID int CheckedAActive bit Checked Unchecked
I've inherited an application that has a query that typically bombs out due to a deadlock in SQL Server 2005. I know where the resource contention is, and why the deadlock happens, and why SQL picks this query to fail, so that's all cool with me. My problem is that I'm in the process of modifying this query to be a little less resource intensive, and I'm getting two different result sets.
The original query is returning 1234 rows, and my first replacement query attempt is returning 930. My replacement query attempt is using a derived table (subquery) rather than copying into a temp table (as the original query is doing). I understand what the missing rows are and why they are not in the result set, so my question is What is it about my replacement query attempt that is so different from the original query?
I appreciate any advice anyone might have to offer.
Best, B.
/* original query */
Code Block
select * into #response from response where MidEndFlag = 'End'
SELECT COUNT(#response.ResponseID) AS TotalCount, CourseInfo.Subject, CourseInfo.Course, CourseInfo.Sect, CourseInfo.Term, CourseInfo.Enrollment, (COUNT(#response.ResponseID) / (CourseInfo.Enrollment * 1.00))* 100 AS Percentage, #response.MidEndFlag FROM #response FULL OUTER JOIN CourseInfo ON #response.Term = CourseInfo.Term AND #response.Subject = CourseInfo.Subject AND #response.Course = CourseInfo.Course AND #response.Sect = CourseInfo.Sect WHERE (courseinfo.InstructorSelectionEndFlag = 'Y') and CourseInfo.Enrollment > 0 and courseinfo.term = @term GROUP BY CourseInfo.Subject, CourseInfo.Course, CourseInfo.Sect, CourseInfo.Term, CourseInfo.Enrollment, #response.MidEndFlag; /* end original query */
/* my first replacement query attempt */
Code Block
SELECT COUNT(r.ResponseID) AS TotalCount, c.Subject, c.Course, c.Sect, c.Term, c.Enrollment, (COUNT(r.ResponseID) / (c.Enrollment * 1.00))* 100 AS Percentage, r.MidEndFlag FROM (select * from dbo.Response where MidEndFlag = 'End') r full outer join CourseInfo as c ON r.Term = c.Term and r.Subject = c.Subject and r.Course = c.Course and r.Sect = c.Sect WHERE c.InstructorSelectionEndFlag = 'Y' and c.Enrollment > 0 and c.term = @term and r.MidEndFlag = 'End' GROUP BY c.Subject, c.Course, c.Sect, c.Term, c.Enrollment, r.MidEndFlag;
In Enterprise Manager, I would right click on the table, choose Open Table and Query where I could select specific records and (most importantly) could alter data in a record by deleting the text, adding or over-typing.
In 2005 Server Management Studio I just cannot figure how to do this. I'm guessing that I need the 'Script Table as' option but then what?
I have managed to open selected data using the New Query and then Design Query in Editor, but the results only appear in a kind of view form and I cannot seem to alter any of the data entries, I get dotted lines around the selected field.
The following was not written by me but I need to modify it and I am definitely no expert in SQL. It returns a list of files that a user is allowed to access based on whether or not they belong to a specific user group and that group has been granted access to the file.
FROM AnswerFile AS a INNER JOIN User AS u ON a.UserID = u.ID
WHERE (a.UserID = 2) AND (a.ID NOT IN SELECT AnswerFileID FROM GroupAnswerFile))
I need to modify this code to add an additional check. I have added a file that allows specific users to be granted access to files. It is called AnswerFileUser and contains AnswerFileID (the file) and UserID (the user that has been given access). I need the query to return as part of the results those files where a user has been given access regardless of their group or group access. I hope this all makes sense. Thanks for your help!
How do you change the time out value for a specific connection? I'm having problems when I connect to SQL Server from my website and I want to test if this would help.
How do I modify data in a sqlDataSource object (like inserting records, editing, deleting) similiary to how I modify data in a GradView using a DataList or repeater? I want to be able to have my own EditTemplate and be able to edit say four fields while I'm only viewing like two of them in the datalist/repeater. <asp:DataList ID="DataList1" runat="server" DataKeyField="GameId" DataSourceID="SqlDataSource1" RepeatColumns="1"> <ItemTemplate> <%# Eval("field1") %><%# Eval("field2") %>.... </ItemTemplate> <EditTemplate>......</EditTemplate>
When I'm trying to add a edit-button (<asp:Button runat="Server" ID="EditButton" Text="Edit" CommandName="Edit" />) and click it nothing happens....What is missing?
I have a DTS was created by another programmer which is for move online Database to a offline Database and now I have to modify it the DTS package have 1 Source DB and 63 distinateDB between SourceDB and DistinateDB are "Black Line" and almost of DistinateDB have a green line between a Task ( excute SQL work) -- some of SQL work are Delete Table and some are Truncate Table and now I have to add some limits for the DTS 1. First, move all the Data From online Database to Offline Database 2. to Delete Data from online DB , Online Database will only keep Data for 6 months ( older than 6 months have to delete except table A and table B) can you help me? or tell me where have a reference information I can take a look... have no idea how to modify this DTS package..
When you first come into the web page I want to exam the querystring and the modify the SQL Statement accordingly in a SQLDatasource.What is the right event of the SQLDataSource to modify the SQLDataSource.SelectCommand = MySQLString property?Thanks
I have a problem with a publication which is a transactional replication on SQL Server 7.0 . I want to add stored procedure to the existing publication along with the tables . But the Enterprise manager does not allow to select or check the box against the required stored procedure although it displays when i right click on the publication and select proeprties .
Can i have some help in this regard ? Does anybody knows to add a stored procedure by means of a query .
Is there any other way to modify publication in SQL Server 7.0 although it is possible in SQL Server 2000 .?
1) Mothly :- -payday is equal to @today -pay frequency is = 1 -payday between 1-31
2) Weekly -payday is between 1-5 ( 1 =Monday,2 =Tuesday,3=Weds,4=Thurs,5=Friday) -payfrequency is = 2
3) Fortnightly -after two weeks -payfrequency =3
How do l modify this procedure to be able to extract using the listed conditions ? Need help
CREATE Procedure Collections_Cats AS BEGIN
Declare @today int Set @today = (SELECT Day(GETDATE()))
DECLARE Collections_Cats_Cursor CURSOR FOR SELECT distinct n.loan_No AS Loan_No, n.customer_No AS Customer_No, c.first_name AS First_name, c.second_name AS Second_name, c.surname AS Surname, c.initials AS Initials, b.Bank_name AS Bank_name, br.branch_code AS Branch_code, d.bank_acc_type AS Bank_acc_type, pay_sheet.pay_frequency AS Pay_Frequency, n.monthly_Payment AS monthly_Payment, pay_sheet.payday AS payday FROM Transaction_Record tr
INNER JOIN Loan n ON tr.loan_No = n.loan_No INNER JOIN Customer c ON n.customer_No = c.customer_no INNER JOIN Bank_detail d ON c.customer_no = d.customer_no INNER JOIN Branch br ON d.Branch = br.Branch INNER JOIN Bank b ON br.Bank = b.Bank INNER JOIN pay_sheet ON c.customer_no = pay_sheet.customer_no WHERE Pay_sheet.Payday = @today AND pay_sheet.pay_frequency =1
Order by l.loan_No
OPEN Collections_Cats_Cursor
-- Perform the first fetch. FETCH NEXT FROM Collections_Cats_Cursor
-- Check @@FETCH_STATUS to see if there are any more rows to fetch. WHILE @@FETCH_STATUS = 0 BEGIN -- This is executed as long as the previous fetch succeeds. FETCH NEXT FROM Collections_Cats_Cursor END
CLOSE Collections_Cats_Cursor DEALLOCATE Collections_Cats_Cursor END; GO
i have a replication job going on for one particular table from one server to another now i have added two new columns in source and replication works fine. once i add these two new columns in destination the replication is failing.
i went to properties of the publisher and select the filter columns where i can find all the columns checked except the two new columns when i try to select these two its not responding pls help me in this.
I am using Sql server 2005, i am trying to find out all the tables that modified recently. i cant find any last modified date!!.
My situation is; i have altered so many tables, usually when i do alter i save the sql file for doing the same alteration in the production database. but somehow i lost the scripts and i am not sure what are the tables that i have modified and what is new.
I have converted Access database to sql express. Access Database had AutoNumber FIelds for which trigger was generated by Upsizing wizard.
Now when I import data from client the autonumber field value changes because trigger is fired which distroys all links
I want to modify trigger so that it generates new number only when it is not supplied in a insert command.
Please help. Code is given below. Also suggest how to save because when I use save, it asks for a new .sql file name and a new file is generated instead of modifying the same trigger
set ANSI_NULLS ON set QUOTED_IDENTIFIER ON GO ALTER TRIGGER [dbo].[T_AcControlLimit_ITrig] ON [dbo].[AcControlLimit] FOR INSERT AS SET NOCOUNT ON DECLARE @randc int, @newc int /* FOR AUTONUMBER-EMULATION CODE */ /* * RANDOM AUTONUMBER EMULATION CODE FOR FIELD 'IntAcControlCode' */ SELECT @randc = (SELECT convert(int, rand() * power(2, 30))) SELECT @newc = (SELECT IntAcControlCode FROM inserted) UPDATE AcControlLimit SET IntAcControlCode = @randc WHERE IntAcControlCode = @newc
Hi all,I have been left to modify an old unique index, which no longer works,as the two fields, which were used, are no longer unique. I’ve found twoothers that are unique. But as I’m new to this I need some advice first.What happens if one table inserts from another (the second containingthe index). However if there is a duplicate will the records which arenot duplicates be inserted? How could I insure this?ThanksSam*** Sent via Developersdex http://www.developersdex.com ***Don't just participate in USENET...get rewarded for it!
I initially modified the column 'ID' from not allowing NULL to allow, and saved it. But now I will like to change it back to 'not allow'. But it gives me the following error message when I try to save my changes:
'Pages' table - Unable to modify table. Cannot insert the value NULL into column 'ID', table <databasename>.Tmp_Pages'; column does not allow nulls. INSERT fails. The statement has been terminated.
I am trying to create a report with unknown number of report items. (as I dont know how many columns the stored proc is going to return).Is there a way to create these type of reports using SSRS other than creating the rdl programatically using vb.net or c#?
HiI have developed a sql procedure for updating some xml content using SQL 2005 xQuery features.For example:Declare @xmlContent = '<books><book name="asp"/>< book name = "sql"/></books>'--Now I want to add attribute "book_id" to the xml content.SET @xmlContent.modify('insert attribute book_id{"1" } into (/books/book[@name="asp"])[1] ')SET @xmlContent.modify('insert attribute book_id{"2" } into (/books/book[@name="sql"])[1] ')SELECT @xmlContent--OUTPUT will be<books><book name="asp" book_id="1"/><book name="sql" book_id="2"/></books>QUESTIONQ1. Do we have any extension or plugin such that this SQl 2005 xquery feature can be incorporated in SQL 2000?Q2. If the answer for Q1. is no (as I expect), then do we have any TSQL feature in SQL 2000 for modifying xml content?I found all examples in SQl 2000 related with "openxml" function which performs the select kind of operations only. Like selecting data in XML format OR converting xml data in to tabular format. But I couldn't find any xml modification TSQL in SQl 2000 which can add element/attributes or change values.one workaround could be to consider xml content as string and use string functions to modify the content.But is there any more sensible approach available in SQL 2000?
Hi, Below is the SP that I want to modify it such that it does another thing apart from what its doing now. I want to to delete all the records corresponding to the BpDate value before this insert happens. by meaning deleting all the records, I meant to say delete all records where BpDate = @BpDate and SiteCode = @SiteCode.
Within a trigger, is it possible to modify a row before it is inserted in SQL Server 7? I need to update two columns before the row is inserted by the trigger.
Hello I have replicated 1 database.Now i need to change the datatype length of one feild from varchar 12 to varchar 20.But when i try to do that it shows error ODBC error !Cannot modify database because it is in replication mode. Can any body help me to sort out this problem. Thx Bilal
Folks, i have rebuilt my old server machine and i've restored the MSDB over the new machine. Now when i try to edit or delete any of the jobs that come from the RESTORE; i get the following error message:
I never setup multiserver administration. However i can create and delete new jobs. How do i remove these older jobs.
Sigh, probably simple, but somehow I just can't get it to work..
I have a complex view which generated about 9000 results, and I use a SP to select certain results from that view. How can I modify the results of the SP? for example I want to add a zero to every single companynumber the SP gives me...
*it's friday, i know* Any help would be appreciated!
I face a task to edit definition for bunch of sp: cleaning <IF EXISTS THEN DROP> and changing CREATE for ALTER.
Do you think there is a good way to do it in batch and take original source from system.tables (even we have this as physical file in VSS)?
Surely enough <IF Exists then drop> is not uniformed, could be variations with syntax and on diff number of lines, IF Exists... vs OBJECT_ID is not null etc...
CREATE__sp_PROCEDUREA vs CREATE_spPROcedure (with diff spacing).
Hi AllAm new to sql server to sobear with me, have checked around but cantfind an answer to this.I want to change fieldname from nvarchar(50) to nvarchar(255) as partof a scriptAm running this command :ALTER TABLE MYTABLE MODIFY fieldname nvarchar(255) nulli test this out in the sql window but cant get it to run error is:Msg 102, Level 15, State 1, Line 1Incorrect syntax near 'MODIFY'.Can anyone help ?
I have a 3rd party program that creates some tables in my sql server2005 database, then it does inserts on the tables. Is there a way Icould create a system level trigger that would immediately andautomatically modfiy the table structure after the table is created(hopefully before the inserts occur)? I need to change a field fromnumeric(5, 0) to numeric(15, 0).Thanks,Roger
my aim is to modify the two fields to change its data type. BUt when im trying to run this command in the query analyzer, itsays "incorrect syntax error '(' "