Rollup Query Help

Jul 20, 2005

I found this great rollup query example that uses grouping and sub
totals. Would it be possible to expand on this and include a group
within a group and subtotal each group? For example, parent product then
child product? Help appreciated. Thanks.
Frank

SQL:
SELECT
CASE
WHEN (Grouping(CategoryName)=1) THEN 'MainTotal'
ELSE CategoryName
END AS CategoryName,

CASE
WHEN (Grouping(ProductName)=1) THEN 'SubTotal'
ELSE Productname
END AS ProductName,

Sum(UnitPrice) as UnitPrice,
Sum(UnitsinStock) as UnitsInStock

FROM Products
INNER JOIN Categories On
Products.CategoryID = Categories.CategoryID
GROUP BY CategoryName, ProductName WITH ROLLUP




*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

View 1 Replies


ADVERTISEMENT

Repetition In Rollup Query

Mar 14, 2008

How do I remove repetitive value in my query with rollup result

a b c 10
a b c 10
a b null 20
x y z 10
x y z 10
x y null 20
null null null 40

View 3 Replies View Related

With RollUp Question

Jul 14, 2006

I am trying to do a Total Row with Rollup.

I am encountering an error:
Server: Msg 8120, Level 16, State 1, Line 25
Column 'CALLSTARTTIME' is invalid in the select list because it is not
contained in either an aggregate function or the GROUP BY clause.

Here's the query:
SELECT
           
CASE WHEN (GROUPING(DATEPART(yy, CALLSTARTTIME))=1) THEN 'Total'
ELSE
    DATEPART(yy, CALLSTARTTIME)
END AS 'Year',
        Count(*) as 'Total Calls'
        FROM         CALL_LOG_MASTER
        GROUP BY DATEPART(yy, CALLSTARTTIME) with ROLLUP
        ORDER BY DATEPART(yy, CALLSTARTTIME)

Idea outcome:

Year   Total Calls
2005   100  
2006   200
Total   300

View 5 Replies View Related

SQL Rollup In Datagrid

Jul 13, 2005

Hi,I am attempting to achieve some form of report that needs to make use of sql rollup and display it as follows:Category     Subject Matter1     Subject Matter2     Subject Matter3     No of CasesClubs             Facilities             Sport Facilities          Swimming Pool       3                     SubTotal                                                                     3Events             SBR/AHM                NULL                      NULL                1                     SubTotal                                                                     1                     GrandTotal                                                                     4However, with my sql query, using roll up, it will look like the following which is not correct.Category     Subject Matter1     Subject Matter2     Subject Matter3     No of CasesClubs             Facilities             Sport Facilities          Swimming Pool          3Clubs             Facilities             Sport Facilities             NULL                      3Clubs             Facilities             NULL                         NULL                      3Clubs             Sub Total             NULL                         NULL                      3Events             SBR/AHM             NULL                         NULL                      1Events              SBR/AHM             NULL                         NULL                     1Events             SBR/AHM             NULL                         NULL                      1Events             Sub Total             NULL                         NULL                      1This is the query I am using:<code>select casewhen (grouping(Cat.Description)=1) then 'Grand Total'else Cat.Descriptionend as Category,casewhen (grouping(sub.description)=1) then 'Sub Total'else Sub.descriptionend as SM1,SubSub.Description as SM2, SM.Description as SM3, count(sub.description)from tb_feedbackcase FB left join tb_category Cat on FB.Category_ID = Cat.Category_ID left join tb_subcategory Sub on FB.SubCategory_ID = Sub.SubCategory_IDleft join tb_subsubcategory SubSub on FB.SubSubCategory_ID = SubSub.SubSubCategory_IDleft join tb_SubjectMatterLV3 SM on FB.SM3_ID = SM.SM3_IDwhere fb.commenttype_id in (select commenttypes_id from tb_comment_types where description = @feedback_type)and convert(char(10),feedback_datetime,102) >= convert(char(10),@date_from, 102)and convert(char(10), feedback_datetime, 102) <= convert(char(10),@date_to, 102)group by Cat.Description, Sub.Description, SubSub.Description, SM.Description with rollup</code>How can I change it to reflect more accurately? Please help. Thanks.

View 1 Replies View Related

RollUp Not Working !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

May 27, 2002

l would like to get totals at the bottom of the following columns

SELECT sum(capital_Amount) AS Capital_Amount,
sum(interest_Amount) AS Interest_Amount,
sum(total_Amount) AS Total_Amount,
sum(admin_Fee) AS Admin_Fee

to sum up all totals by column. i tried using the rollup,cube like in oracle no luck. Whats the best way of achieving this? if l have to write it as a function how would l do that?

Alter View Test2
As
SELECT loan_No AS Loan_No,
date_Issued AS Date_Issued,
store AS Store,
product AS Product,
capital_Amount AS Capital_Amount,
interest_Amount AS Interest_Amount,
total_Amount AS Total_Amount,
admin_Fee AS Admin_Fee,
user_Issued AS User_Issued,
LoanBook AS Company,
status
FROM Loan

View 2 Replies View Related

Rollup Records?

Jun 22, 2004

I have two tables - the first contains machine info, and the second contains monthly readings.

Table1
Serial, Model, Location, etc...

Table2
Serial, Year, Month, Reading

I would like to write a query that gives me one row for each machine that has the serial, model, and the reading for the previous 12 months. The date will be passed into the query

Query (passing 6/1/2004)
Serial, Model, ReadingFor200307, ReadingFor200308, ...., ReadingFor200406

Can anyone help me with this or tell me what topic I should be scanning the help files for?

Thanks,

Rob

View 1 Replies View Related

Order By In The Rollup

Oct 7, 2004

Ok, I want to know if it is possible to do an order by while using the rollup in the group by. Look at the below script:


create table tmpTable
(
prod_name varchar(50) null,
prod_color varchar(50) null,
quantity int null
)

insert into tmpTable values ('table', 'blue', 12)
insert into tmpTable values ('table', 'red', 100)
insert into tmpTable values ('table', 'white', 50)
insert into tmpTable values ('chair', 'blue', 12)
insert into tmpTable values ('chair', 'red', 1)
insert into tmpTable values ('chair', 'white', 123)
insert into tmpTable values ('chair', 'yellow', 50)

SELECT CASE WHEN (GROUPING(prod_name) = 1) THEN 'Grand Total'
ELSE ISNULL(prod_name, 'UNKNOWN')
END AS Item,
CASE WHEN (GROUPING(prod_color) = 1) and grouping(prod_name) != 1 THEN 'Sub Total'
when grouping(prod_color) = 1 and grouping(prod_name) = 1 then ''
ELSE ISNULL(prod_color, 'UNKNOWN')
END AS Color,
SUM(quantity) AS QtySum
FROM tmpTable
GROUP BY prod_name, prod_color WITH ROLLUP

--drop table tmpTable


I want to be able to do an order by for each section of the rollup so that the quantity can be asc for both the chair part of the query and the table part.

Thanks ahead of time.

DMW

View 2 Replies View Related

What Is CUBE And ROLLUP???

Sep 16, 2007



Hi,
Can anyone explain me that WHAT IS CUBE AND ROLLUP Statments for?? Why to use, Where to use and When to use???
Are they usefull in any point of view from ADO.NET???

View 5 Replies View Related

How To Use Rollup On Only 1 Column

Mar 28, 2008

I would like to only have 1 column rollup but I still need the other columns in the output. Here is my T-SQL code:

This is the current output:

0 2007-02-14 00:00:00 test test 03-Barnes Healthcare Services 246.00
0 2007-02-14 00:00:00 test test 03-Barnes Healthcare Services 246.00
0 2007-02-14 00:00:00 test test NULL 246.00
0 2007-02-14 00:00:00 test NULL NULL 246.00
0 2007-02-14 00:00:00 NULL NULL NULL 246.00
...
...
0 NULL NULL NULL NULL 3992230.50

I would like it to look like this:

0 2007-02-14 00:00:00 test test 03-Barnes Healthcare Services 246.00
..
...
0 NULL NULL NULL NULL 3992230.50

I only want the total on the 1st column, but it rollups all of the columns.






Code Snippet

SELECT ServiceTypeCode, ServiceDate, IFirst, ILast, VendorName, Sum(ISNULL(AfterDiscountAmt,0)) AS Amount
FROM Holding_Billable
WHERE DocumentDate BETWEEN '1/1/2007' AND '12/31/2007'
AND SiteCode = 7001
GROUP BY ServiceTypeCode, ServiceDate, IFirst, ILast, VendorName, AfterDiscountAmt
WITH ROLLUP

View 1 Replies View Related

Rollup Question, What's Wrong?

Jul 6, 2004

So I'm making some kind of vain attempt to follow this tutorial to get summary rows, and I've followed it as best I can to the letter using my own data. But when I try to run the query, it tells me there's a syntax error near "WITHROLLUP". Am I missing something?


SELECT CASE GROUPING(Employee) WHEN 0 THEN Employee ELSE 'Total' END AS TheEmployee, CASE GROUPING(ID)
WHEN 0 THEN ID ELSE - 1 END AS TheID, SUM(WorkDays) AS TotDays
FROM EmpScheduleExceptions
WHERE (YEAR(Start) = YEAR(GETDATE()))
GROUP BY Employee, ID WITH ROLLUP
ORDER BY Employee, TotDays

View 4 Replies View Related

COUNT(DISTINCT) With ROLLUP

Aug 17, 2005

I'm struggling to fin a way to use DISTINCT keyword with ROLLUP (or Cube).For example,SELECT employee_city, employee_country, COUNT(DISTINCT employee_name)FROM employeeGROUP BY employee_city, employee_country WITH ROLLUPthat query does not work.Is there a workaround?Thx.

View 2 Replies View Related

Rollup Child Rows?

Sep 26, 2005

Is it possible to roll up all child records into one comma delimited field? For example, if the parent table is league info, and the child table is team info, I would be looking to return results like this:

Field 1 Field 2
NFL Bears, Browns, Saints, etc
NBA Bulls, Celtics, Lakers, etc

TIA,

Rob

View 4 Replies View Related

Rollup Multiple Records Into One?

Jan 16, 2004

I have a two tables - a machine, and a volume

Machine has id, and serial number fields
Volume has machine_id, date, and volume

I need to roll up each volume reading into quarters for the year, and return each machine and all its quarters.

So the output should look like this (only one year will be run):

MachineID Qtr1SUM(Volume) Qtr2SUM(Volume) Qtr3SUM(Volume) Qtr4SUM(Volume)


Any ideas? I was going to join the volume table four times, with each one making sure it had the appropiate dates, but that isn't working well.

Thanks,

Rob

View 4 Replies View Related

What Is The Purpose Of Cube And ROLLUP?

Mar 30, 2007

Hai all !

What is purpose of Cube and Rollup?
Can u explain with small example?

Regards
Umapathy

Umapathy

View 1 Replies View Related

Cube/Rollup Without Group By?

Jul 20, 2005

MS has been nice enough to add the Cube and Rollup operators so I canhave totals with my results.But out of shear meanness they won't let me use them unless I use aGroup By clause in my select. I have a proc with 25 fields, and haveno desire to Group By anything- when a certain field changes, I justwant a row with the total of that field.Is this possible?Thanks,Burt

View 2 Replies View Related

Total/subtotal SQL ROLLUP Question

May 3, 2004

I am using the SQL GROUP BY WITH ROLLUP PER MS's

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndive/html/data01102002.asp

To create subtotals and totals.

The problem is, I want items on every line, like transaction dates, that are neither grouped by or summed. They are just for information only.

ANSI-92 SQL does not allow any column to be selected that is either not grouped on or has an aggregate function performed.

The MS example in the link above works fine, but does not present much data.

If I wanted to sum total orders and each order's subtotal for a given customer, I would also likely want the order date, who the order was placed by, etc. in each line of the report without grouping or summing that extraneous info.

Here is an example of the SQL syntax:

SELECT
CASE GROUPING (companyId) WHEN 0
THEN (SELECT CFP..Company.companyName FROM Company WHERE Company.companyId = Activity.companyId) ELSE 'TOTAL' END AS [Company name],
CASE GROUPING (dateOrder) WHEN 0
THEN (SELECT CAST(dateOrderAS VARCHAR)) ELSE 'SUB TOTAL' END AS [dateOrder],
SUM(transactionAmount) AS [Request amount]
FROM Activity
WHERE DATEPART(year, dateOrder) = DATEPART(year, '2004')
GROUP BY companyId, dateOrderWITH ROLLUP

...

But I want more details.

View 1 Replies View Related

Rollup Unary Create A New Column

Jun 22, 2005

after I've created a new column in a table with the "Create a new column" with custom members. How do I actually remove this newly created column without recreating the dimension ?

Thank you
Tom

View 1 Replies View Related

Compute Command Change To Rollup?

Aug 25, 2014

i want this keep query output result but don't want the "compute " this command , because this query cannot run in this dos command directc.exe , Thus, it is have any writing skill , it is possible using of rollup ?

select d.shopcode
,d.memono
,d.txdate
,d.sku
,h.depositamt

[Code] ....

View 2 Replies View Related

Grouping Sets Sample With Rollup

Sep 4, 2014

How to writing this query using rollup or grouping sets in two way?

data
shop time date sku discount% sales qty amount
A 13:00pm, 2014-feb-11 apple 30% 5 #20
A 13:00pm, 2014-feb-11 apple 30% 5 #20
A Shop Qty :10 Amt:40
B 23:00pm, 2014-feb-11 apple 30% 5 #20
B 23:00pm, 2014-feb-11 apple 30% 5 #20
B shop Qty :10 Amt $40
Grand total qty:20 , Amt $80

View 1 Replies View Related

Multiple Type Rollup By Column

Nov 29, 2007



I'm trying to create a report where multiple currencies are rolled up into seperate subtotals. The currency type and amount are in seperate columns..

I'd like for my report to look like this
Account currency_type ammount

I'd like for the report to look like this
001 USD 100
001 USD 150
001 EUR 100
001 EUR 100
001 AUD 100
Total USD 250
EUR 200
AUD 100


Is there a way to do this?

View 10 Replies View Related

Why Counts Multipled For 'Select.. Count And Group With Rollup?

Apr 10, 2008

I have been working on this 'Select Count' problem for the past week.  Somehow, the Counts were multipled.2 requests showed 4 counts, 3 requests showed 9 counts, 4 requests showed 16 counts. The main question,to the best of my knowledge, is the coding for DBadapter.Fill method.   After 'Left Join' 2 tables, how do I code the DataTable names?   I have tried using TransDS.Tables("Table name") to solve the problem. Butthe counts still showed mulpile #. 
Another question: why there are 1 '0' line and 2 'rollup' lines?  




Examiner
Requested
Scheduled
Finished
noShow
Cancelled
Deleted

 
0
0
0
0
0
0

 
312
249
97
60
39
45

 
255
210
90
60
15
30

 aaaa
4
4
0
0
0
0

 bbbb
9
9
3
0
6
0

 
16
16
0
0
16
0

 
16
4
2
0
2
12

 
4
4
2
0
0
0
  strApptsSQL = "SELECT c.LName + ', ' + c.FName AS Examiner, " & _
"COUNT(Case TransCode WHEN 'R' THEN 1 ELSE NULL END) AS Requested, " & _"COUNT(Case TransCode WHEN 'B' THEN 1 ELSE NULL END) AS Scheduled, " & _
"COUNT(Case TransCode WHEN 'F' THEN 1 ELSE NULL END) AS Finished, " & _"COUNT(Case TransCode WHEN 'W' THEN 1 ELSE NULL END) AS DSnoShow, " & _
"COUNT(Case TransCode WHEN 'D' THEN 1 ELSE NULL END) AS Deleted, " & _"COUNT(Case TransCode WHEN 'E' THEN 1 ELSE NULL END) AS Cancelled " & _
"FROM Sssss.dbo.TransHistory AS T " & _"LEFT JOIN Sssss.dbo.Requests AS r ON T.TransUserID = r.RequestStaffIDFK " & " " & _
"LEFT JOIN Employee.dbo.Contacts AS c ON r.RequestStaffIDFK = c.ContactPK " & " " & _"GROUP BY c.LName + ', ' + c.FName WITH ROLLUP " & _
"ORDER BY c.LName + ', ' + c.FName"
'declare and create the data adaptersDim oDAAppts As New OleDbDataAdapter(strApptsSQL, oConnect)
Try
' fill the Dataset using the data adaptersoDAAppts.Fill(TransDS, "Requests")
Catch oErr As Exception
' display error message in page
lblErr.Text &= oErr.Message & "<br />"
Finally
' be sure to close connection if error occurs
If oConnect.State <> ConnectionState.Closed Then
oConnect.Close()
End If
End Try
' bind DataGrid to tablegvExaminerAppts.DataSource = TransDS.Tables("Requests")
gvExaminerAppts.DataBind()
 

View 2 Replies View Related

SQL Server 2005 SP2 Update 2 Rollup Performance Tank

Oct 25, 2007

I installed the SQL Server 2005 SP2 update 2 rollup on my 64-bitserver and the performance has tanked!I installed rollup 3 on some of them, but that did not seem to help.I thought it was just a linked server performance issue, but myoptimization started running today on one of the "update 2" instancesand so far it's been running about 10 hours longer than it normallydoes.The rollup 3 fixed our stack dumping issues, but we NEED to have thisperformance thing fixed!I saw that MS has come out with update 4 last week - doesn't sayanything about fixing this, though.Has anyone else experienced this?I'm not necessarily expecting anyone to have a fix for this, justwantto know I'm looking in the right place before I call MS.

View 3 Replies View Related

Custom Rollup Formulas On Analysis Services 2005

Aug 29, 2007

Hello all, I´m a beginner on AS2005 (but I know pretty well AS2000), I migrated a cube from AS2000 to AS2005 but in this cube I have a Custom Rollup Formula on two levels of my Time dimension (month and week), an example of the week level formula is the next:
iif( [Time].CurrentMember.Name = [Time].CurrentMember.NextMember.Name,
null,
iif( [Time].CurrentMember.Name = [Time].CurrentMember.PrevMember.Name,
Sum({[Time].CurrentMember.Children,[Time].CurrentMember.PrevMember.Children}),
Sum([Time].CurrentMember.Children)
)
)
<<this formula overrides the week aggregations>>

and I really need this but I cannot find on AS2005 where to do the same thing, someone can tell me where can I define Custom Rollup Formulas and how?.
Thanks in advance!

View 10 Replies View Related

Daily Report Generating Monthly Rollup Stats

Jan 2, 2007

Daily report generating Monthly rollup stats

I have a daily report which each morning generates monthly information for the current month which was implemented in December. Everything was working correctly untill January 1st. On the 1st the report generated blank since it was suppose to generate 1-31 Dec but but the currently month was Jan, so it failed. How do I program it so if it is the 1st of a month generates the previous month but still would generate current month but while in the current month? Any help is appreciated.


SELECT GETDATE() - 1 AS rptdate, Errors.WTG_ID, lookup.Phase, Errors.STATUS_TYPE, Errors.STATUS_CODE, STATUS_CODES.STATUS_DEF, Errors.TIME_STAMP,
Errors.ANSI_TIME, lookup.WTG_TYPE, Errors.POSITION
FROM Errors INNER JOIN lookup ON Errors.WTG_ID = lookup.WTG_id RIGHT OUTER JOIN STATUS_CODES ON Errors.STATUS_CODE = STATUS_CODES.STATUS_CODE AND lookup.WTG_TYPE = STATUS_CODES.WTG_TYPE
WHERE (STATUS_CODES.STATUS_DEF IS NOT NULL) AND (Errors.TIME_STAMP BETWEEN DATEADD(mm, DATEDIFF(mm, 0, GETDATE()), 0) AND DATEADD(mm, DATEDIFF(m, 0, GETDATE()) + 1, 0))
ORDER BY Errors.WTG_ID, Errors.TIME_STAMP, position

View 5 Replies View Related

Analysis :: Ragged Hierarchy - Unary And Custom Rollup Calculations

Aug 13, 2015

Any working example of what a ragged hierarchy should look like for the unary and custom rollup calcs to work?

I have a parent-child hierarchy that works as expected but can't manage to get the same with a flattened ragged hierarchy. Parents disappear if any of the children aren't in the fact table (even though the children are set to '~' and the parent has its own custom rollup calc).

Do I need to replicate the unary and measure formula all the way to the end in the same way i do the member name/value (so i can set ignore if same as parent)? Setting unary to null seems to work when the key doesnt exist in the fact table but the default behaviour for null is '+' so i end up getting wrong results if the key does exist!

Repro:

In words

I have an EAV style fact table. The measure name is defined in a 'dim measure' table. Some measures exist in the fact, some are manufactured using Unary ops or custom rollup formulas.

Here's a diagram of the hierarchy

I want to recreate the functionality as a flattened hierarchy (the number of levels is fixed), but can't seem to do it... Here's what I've gotten for the same hierarchy created using the two different approaches

Below are queries to recreate the tables from adventureworksdw2014. The parent child hierarchy is set up the standard way... measureparentkey is parent. set name, unary and formula as expected. Set NonLeafDataHidden for the parent attribute. I've tried various combinations for the ragged hierarchy but none work 100% of the time. I want to have a user defined hierarchy for the performance benefits.

--Fact view
CREATE View dbo.FactSales
AS
select fis.ProductKey
, fis.OrderDateKey
, 1 AS MeasureKey -- salesAmount
, fis.SalesAmount AS MeasureValue

[Code] .....

View 3 Replies View Related

ROLLUP - Retrieve A List Showing Total Repair Cost Per Year

Mar 1, 2014

I have a question regarding ROLLUP and how to use the operator.

I've been asked to retrieve a list showing the total repair cost per year displaying Transport Type, Manufacturer and Transport. The query I used is:

SELECT ty.Description AS TransportDescription,
t.SerialNumber AS Transport,
ty.Manufacturer,
SUM (r.RepairCost) AS RepairCost,
YEAR(r.EndWorkDate) AS [Year]

[Code] .....

How could I use the rollup function to display subtotals per Transport Type, Manufacturer and Transport?

View 1 Replies View Related

Query Runs Fine In Query Analyser But Not The Query Debugger

Dec 19, 2003

I'm running a query, actually its an insert that works when using the TSQL below.

However when I try to use the debugger to step through and using the exact same values as those below I get the following error:

[Microsoft][ODBC SQL Server Driver]Invalid character value for cast specification

Its Killing me because everything else works, but this. Can somebody help.


DECLARE @NoteID INT,-- NULL OUTPUT,
@Note_Description NVARCHAR(3000),-- = NULL,
@Date DateTime,-- = NULL OUTPUT,
@ByWho NVARCHAR(30),-- = NULL,
@FK_Action_Performed NVARCHAR(40),-- = NULL,
@FK_UserID INT,-- = NULL,
@FK_JobID INT,-- = NULL,
@Job_Date DateTime,-- = NULL,
@Start DateTime,-- = NULL,
@Finish DateTime,-- = NULL,

@BeenRead NVARCHAR(10),-- = NULL

@FK_UserIDList NVARCHAR(4000)-- = NULL


--SET @NoteID = 409 --NULL OUTPUT,
SET @Note_Description = 'Tetsing'
--SET @Date DateTime = NULL OUTPUT,
SET @ByWho = 'GeorgeAgaian'
SET @FK_Action_Performed = 'Worked hard'
SET @FK_UserID = 5
SET @FK_JobID = 29
SET @Job_Date = 28/01/03
SET @Start = '1:00:20 PM'
SET @Finish = '1:00:20 PM'
SET @BeenRead = 'UnRead'

SET @FK_UserIDList = '1,2,3'


--AS

--SET NOCOUNT ON


SET NOCOUNT ON

SET XACT_ABORT ON

BEGIN TRANSACTION

SET @Date = GETDATE()

-- Insert Values into the customer table
INSERT Note (Note_Description,
Date,
ByWho,
FK_Action_Performed,
FK_UserID,
FK_JobID,
Job_Date,
Start,
Finish)

SELECT --@NoteID,
@Note_Description,
@Date,
@ByWho,
@FK_Action_Performed,
@FK_UserID,
@FK_JobID,

@Job_Date,
@Start,
@Finish

-- Get the new Customer Identifier, return as OUTPUT param
SELECT @NoteID = @@IDENTITY


-- Insert new notes for all the users that the note pertains to, in this case this will be by the assigned
-- users.
IF @FK_UserIDList IS NOT NULL
EXECUTE spInsertNotesByAssignedUsers @NoteID, @FK_UserIDList

-- Insert New Address record
-- Retrieve Address reference into @AddressId
-- EXEC spInsertForUserNote
-- @FK_UserID,
--@NoteID,
-- @BeenRead
-- @Fax,
-- @PKId,
-- @AddressId OUTPUT

COMMIT TRANSACTION

--------------------------------------------------
GO

View 1 Replies View Related

Query Diff Results From Ent Manager Query And Query Analizer

May 28, 2008

ok can someone tell me why i get two different answers for the same query. (looking for last day of month for a given date)

SELECT DATEADD(ms, - 3, DATEADD(mm, DATEDIFF(m, 0, CAST('12/20/2006' AS datetime)) + 1, 0)) AS Expr1
FROM testsupplierSCNCR
I am getting the result of 01/01/2007

but in query analizer I get the result of

12/31/2006

Why the different dates

View 4 Replies View Related

[Query] - Query Designer Encountered A Query Error:Unspecified Error

Jan 22, 2001

Hi,

I get this error dialog when I try to open all the rows of any table from Enterprise manager..

Any help would be really appreciated..

Thanks,
-Srini.

View 1 Replies View Related

Error: 8624 Internal Query Processor Error: The Query Processor Could Not Produce A Query Plan.

May 24, 2007

SQL Server 2005 9.0.3161 on Win 2k3 R2



I receive the following error:



"Error: 8624, Severity: 16, State: 1 Internal Query Processor Error: The query processor could not produce a query plan. For more information, contact Customer Support Services."



I have traced this to an insert statement that executes as part of a stored procedure.



INSERT INTO ledger (journal__id, account__id,account_recv_info__id,amount)

VALUES (@journal_id, @acct_id, @acct_recv_id, @amount)



There is also an auto-increment column called id. There are FK contraints on all of the columns ending in "__id". I have found that if I remove the contraint on account__id the procedure will execute without error. None of the other constraints seem to make a difference. Of course I don't want to remove this key because it is important to the database integrity and should not be causing problems, but apparently it confuses the optimizer.



Also, the strange thing is that I can get the procedure to execute without error when I run it directly through management studio, but I receive the error when executing from .NET code or anything using ODBC (Access).

View 5 Replies View Related

Query Works In 'test Query' But Refuses To Show Up In The Datagrid On A Web Page - Urgent!

Mar 28, 2007

Hey, i've written a query to search a database dependant on variables chosen by user etc etc. Opened up a new sqldatasource, entered the query shown below and went on to the test query page. Entered some test variables, everything works as it should do. Try to get it to show in a datagrid on a webpage - nothing. No data shows.
 SELECT dbo.DERIVATIVES.DERIVATIVE_ID, count(*) AS Matches
FROM dbo.MAKES INNER JOIN
dbo.MODELS ON dbo.MAKES.MAKE_ID = dbo.MODELS.MAKE_ID INNER JOIN
dbo.DERIVATIVES ON dbo.MODELS.MODEL_ID = dbo.DERIVATIVES.MODEL_ID INNER JOIN
dbo.[VALUES] ON dbo.DERIVATIVES.DERIVATIVE_ID = dbo.[VALUES].DERIVATIVE_ID INNER JOIN
dbo.ATTRIBUTES ON dbo.[VALUES].ATTRIBUTE_ID = dbo.ATTRIBUTES.ATTRIBUTE_ID
WHERE ((ATTRIBUTES.ATTRIBUTE_ID = @ATT_ID1 and (@VAL1 is null or VALUE = @VAL1)) or
(ATTRIBUTES.ATTRIBUTE_ID = @ATT_ID2 and (@VAL2 is null or VALUE = @VAL2)) or
(ATTRIBUTES.ATTRIBUTE_ID = @ATT_ID3 and (@VAL3 is null or VALUE = @VAL3)) or
(ATTRIBUTES.ATTRIBUTE_ID = @ATT_ID4 and (@VAL4 is null or VALUE = @VAL4)) )
GROUP BY dbo.DERIVATIVES.DERIVATIVE_ID
HAVING count(*) >= CASE WHEN @VAL1 IS NOT NULL THEN 1 ELSE 0 END +
CASE WHEN @VAL2 IS NOT NULL THEN 1 ELSE 0 END +
CASE WHEN @VAL3 IS NOT NULL THEN 1 ELSE 0 END +
CASE WHEN @VAL4 IS NOT NULL THEN 1 ELSE 0 END -2
ORDER BY count(*) DESC

 Here is the page source
 
<%@ Page Language="VB" MasterPageFile="~/MasterPage.master" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:DevConnectionString1 %>"
SelectCommand="&#9;SELECT dbo.DERIVATIVES.DERIVATIVE_ID, count(*) AS Matches&#13;&#10;&#9;FROM dbo.MAKES INNER JOIN&#13;&#10;&#9;&#9;&#9;&#9; dbo.MODELS ON dbo.MAKES.MAKE_ID = dbo.MODELS.MAKE_ID INNER JOIN&#13;&#10;&#9;&#9;&#9;&#9; dbo.DERIVATIVES ON dbo.MODELS.MODEL_ID = dbo.DERIVATIVES.MODEL_ID INNER JOIN&#13;&#10;&#9;&#9;&#9;&#9; dbo.[VALUES] ON dbo.DERIVATIVES.DERIVATIVE_ID = dbo.[VALUES].DERIVATIVE_ID INNER JOIN&#13;&#10;&#9;&#9;&#9;&#9; dbo.ATTRIBUTES ON dbo.[VALUES].ATTRIBUTE_ID = dbo.ATTRIBUTES.ATTRIBUTE_ID&#13;&#10;&#9;WHERE ((ATTRIBUTES.ATTRIBUTE_ID = @ATT_ID1 and (@VAL1 is null or VALUE = @VAL1)) or&#13;&#10;&#9;&#9; (ATTRIBUTES.ATTRIBUTE_ID = @ATT_ID2 and (@VAL2 is null or VALUE = @VAL2)) or&#13;&#10;&#9;&#9; (ATTRIBUTES.ATTRIBUTE_ID = @ATT_ID3 and (@VAL3 is null or VALUE = @VAL3)) or&#13;&#10;&#9;&#9; (ATTRIBUTES.ATTRIBUTE_ID = @ATT_ID4 and (@VAL4 is null or VALUE = @VAL4)) )&#13;&#10;&#9;GROUP BY dbo.DERIVATIVES.DERIVATIVE_ID&#13;&#10;&#9;HAVING count(*) >= CASE WHEN @VAL1 IS NOT NULL THEN 1 ELSE 0 END +&#13;&#10;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9; CASE WHEN @VAL2 IS NOT NULL THEN 1 ELSE 0 END +&#13;&#10;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9; CASE WHEN @VAL3 IS NOT NULL THEN 1 ELSE 0 END +&#13;&#10;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9; CASE WHEN @VAL4 IS NOT NULL THEN 1 ELSE 0 END -2&#13;&#10;&#9;ORDER BY count(*) DESC&#13;&#10;">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1" Name="ATT_ID1" PropertyName="SelectedValue" />
<asp:ControlParameter ControlID="TextBox1" Name="VAL1" PropertyName="Text" />
<asp:Parameter Name="ATT_ID2" />
<asp:Parameter Name="VAL2" />
<asp:Parameter Name="ATT_ID3" />
<asp:Parameter Name="VAL3" />
<asp:Parameter Name="ATT_ID4" />
<asp:Parameter Name="VAL4" />
</SelectParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:DevConnectionString1 %>"
SelectCommand="SELECT * FROM [ATTRIBUTES]"></asp:SqlDataSource>
<br />
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource2"
DataTextField="ATTRIBUTE_NAME" DataValueField="ATTRIBUTE_ID">
</asp:DropDownList>
<asp:TextBox ID="TextBox1" runat="server" AutoPostBack="True"></asp:TextBox><br />
<br />
<br />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="DERIVATIVE_ID"
DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="DERIVATIVE_ID" HeaderText="DERIVATIVE_ID" InsertVisible="False"
ReadOnly="True" SortExpression="DERIVATIVE_ID" />
<asp:BoundField DataField="Matches" HeaderText="Matches" ReadOnly="True" SortExpression="Matches" />
</Columns>
</asp:GridView>
</asp:Content>
 AFAIK I have configured the source to pick up the dropdownlist value and the textbox value (the text box is autopostback).
 Am i not submitting the data correctly? (It worked with a simple query...just not with this one). I have tried a stored procedure which works when testing just not when its live on a webpage.
 Please help!
 
(Visual Web Devleoper 2005 Express and SQL Server Management Studio Express)
 

View 4 Replies View Related

SQL Server 2012 :: Adding Count To Query Without Duplicating Original Select Query

Aug 5, 2014

I have the following code.

SELECT _bvSerialMasterFull.SerialNumber, _bvSerialMasterFull.SNStockLink, _bvSerialMasterFull.SNDateLMove, _bvSerialMasterFull.CurrentLoc,
_bvSerialMasterFull.CurrentAccLink, _bvSerialMasterFull.StockCode, _bvSerialMasterFull.CurrentAccount, _bvSerialMasterFull.CurrentLocationDesc,
_bvSerialNumbersFull.SNTxDate, _bvSerialNumbersFull.SNTxReference, _bvSerialNumbersFull.SNTrCodeID, _bvSerialNumbersFull.SNTransType,
_bvSerialNumbersFull.SNWarehouseID, _bvSerialNumbersFull.TransAccount, _bvSerialNumbersFull.TransTypeDesc,

[code]...

However, as you can see, the original select query is run twice and joined together.What I was hoping for is this to be done in the original query without the need to duplicate the original query.

View 2 Replies View Related

Opening Up Odbc Data Source In The Query Query Inside Of The Server Manager

Jun 15, 2007

I'm trying to find the command to open up an odbc conection inside sql2005 express. I only have ues of an odbc connector, we're conection to remedy. We will eventually be using stored procedures to extract the data we need from remedy and doing additional data crunching. I'm a foxpro programmer so once I get the correct syntax for making the odbc connector I shold be ok. Also I need a really good advanced book on sql2005. The type of book that would have my odbc answer. I've spent all morning trying to find this information and was unable to.



Thanks in advance



Daniel Buchanan.



If this was the wrong forum to post this on, please move this question to the correct one. I need this answer soon.

View 1 Replies View Related







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