Viewing 15 posts - 346 through 360 (of 395 total)
You select from the cte at the end, not the beginning:
with cte as
(
select 1 as one, 2 as two from oneTable
),
cte2 as
(
select one, two from cte
union select one +...
August 7, 2012 at 5:08 am
Can you give us an example that relates to the sample data you've posted?
August 7, 2012 at 5:04 am
If you mean you want to keep the original 20 records with extra summed columns, you can do this:
SELECT Work_Id,
Project_name,
country,
region,
Current_Actual_Saving,
Current_Forecast,
Current_Metric,
Prior_Actual_Saving,
Prior_Forecast,
Prior_Metric,
Prior_2_Actual_Forecast,...
August 7, 2012 at 4:42 am
You can roll up selected values and add them to each record like this:
SELECT Country,Region, Current_Forecast,
SUM(Current_Forecast) OVER (PARTITION BY Country, Region) as Sum_Current_Forecast
FROM My_Table
August 7, 2012 at 4:37 am
There's another one here you may not have seen:
http://www.sqlservercentral.com/Forums/Topic952029-391-2.aspx
Seems to go into a bit more depth - again not sure it if it will answer your question...
August 6, 2012 at 2:56 pm
This has been covered recently - may be of some help:
http://www.sqlservercentral.com/Forums/Topic872069-1550-1.aspx
August 6, 2012 at 7:12 am
You can create a script of all stored procedures in a database & search through that. It's easy to see the context & skip from one proc to another.
If...
August 6, 2012 at 5:07 am
Hi
You could use sp_executesql like this:
Test data:
---------------------------------------------
-- Set up test data:
---------------------------------------------
IF OBJECT_ID('dbo.Vendors') IS NOT NULL
DROP TABLE dbo.Vendors;
IF OBJECT_ID('dbo.Invoices') IS NOT NULL
DROP TABLE dbo.Invoices;
CREATE TABLE dbo.Vendors
(
VendorID Int,
VendorName nvarchar(30)
);
CREATE TABLE dbo.Invoices
(
VendorID Int,
InvoiceNumber...
August 6, 2012 at 4:51 am
How about this:
IF OBJECT_ID('dbo.Sales1') IS NOT NULL
DROP TABLE dbo.Sales1;
CREATE TABLE dbo.sales1
(
Sales_saleID int,
Sales_customerID int,
Sales_status varchar(10)
);
INSERT INTO dbo.sales1 VALUES ( 1, 1, 'Pending' );
INSERT INTO dbo.sales1 VALUES ( 2, 1, 'Completed' );
INSERT...
August 1, 2012 at 9:10 am
This is a very old fashioned syntax.
You should use LEFT OUTER JOIN ON ......, RIGHT OUTER JOIN ON ...... etc.
August 1, 2012 at 8:24 am
It's sp_Executesql that's the problem. 1) Are you using the parameter? 2) The format doesn't look right - see:
ms-help://MS.SQLCC.v10/MS.SQLSVR.v10.en/s10de_6tsql/html/a8d68d72-0f4d-4ecb-ae86-1235b962f646.htm
It works as EXEC(@SQLQuery)
August 1, 2012 at 7:12 am
This has been recommended recently & might help...
August 1, 2012 at 5:44 am
Having looked at the article, it looks like the 'AS' clause is in the wrong place. It should be like this, I think
SELECT a.DayCount,
...
August 1, 2012 at 3:41 am
If you've got both 0 & 1 records missing, use the following:
CREATE TABLE ORDERID
(
OrderId Int,
Cost Numeric(9,2),
Indicator int,
[Count] Int
);
INSERT INTO ORDERID VALUES ( 1, 10000, 0, 2 );
INSERT INTO ORDERID VALUES...
July 31, 2012 at 10:27 am
Using a LEFT OUTER JOIN will handle that:
SELECT
ZERO.OrderId, ZERO.Cost, ZERO.[Count],
ONE_COST = ISNULL(ONE.Cost, 000.00), ONE_COUNT = ISNULL(ONE.[Count], 000.00)
FROM
ORDERID ZERO
LEFT OUTER JOIN
(
SELECT
OrderId,
Cost, [Count]
FROM
ORDERID
WHERE
Indicator = 1
) ONE ON ZERO.OrderId = ONE.OrderId
WHERE
ZERO.Indicator...
July 31, 2012 at 10:17 am
Viewing 15 posts - 346 through 360 (of 395 total)