Transact SQL :: Calculate Column Purchasing Rate Per Customer For Product And Region

Oct 22, 2015

I have a table Product2 as the attachment at the bottom. Now i want to create a Column "Purchasing rate" over Product and Region like this. I tried some Code but it gave me still Error.

createtableProduct2
(
[product] [varchar](255),
[Region] [varchar](15),
[Subregion] [varchar](25),

[Code] ....

View 5 Replies


ADVERTISEMENT

Transact SQL :: Multiple Occurrences Of Same Product And Same Customer Filtered By Region

Nov 18, 2015

I successfully used the query below to identify customers that purchased the a specific product (e.g. db1.product_id = '123') on different dates.  Now I need to only pull the purchases from a particular region (client_cd = '593') that purchased a particular product on different dates.  How can I do this?

select distinct T.* from db1 T1
where exists (select 1 from db1 T2 where T2.CustomerId = T1.CustomerId and T2.ProductId = T1.ProductId and T2.PurchaseDate
<> T1.PurchaseDate) and T1.ProductId = '123'<o:p></o:p>

View 3 Replies View Related

Transact SQL :: Multiple Occurrences Of Same Product And Same Customer

Nov 5, 2015

I am trying to build a query to identify customers that purchased the a specific product (e.g. db1.product_id = '123') on different dates.  All of the information needed is in the same db.  How do I do this?

Select db1.customer_id,
db1.product_id,
db1.purchase_date
From db1

View 20 Replies View Related

Transact SQL :: How To Create Column (Region)

Oct 19, 2015

create the column "Region" like this Picture?.

View 26 Replies View Related

Transact SQL :: How To Create Column Region

Oct 14, 2015

How to create column "Region" like this Picture.

View 16 Replies View Related

Transact SQL :: Retrieve Another Column (exchange Rate) From Particular Date For Subquery?

May 25, 2015

Below is the query in which i want to retrieve another column (exchange rate) from a particular date for the sub query. 

Actually PurchaseOrderDet table get records related to purchaseorder but for each row in purchaseorderdet need info from the same table for all rows on a particular date.

how i can achieve this query without using RANK() and other functions.

"SELECT  Supplier.Uniid AS SupplierID, Supplier.Name, PurchaseOrder.Uniid AS PurchaseID, PurchaseOrder.OrderNo, PurchaseOrder.FormDate, StockItem.Uniid AS StockID, StockItem.StockCode + N' - ' + StockItem.Description1 AS StockItem,
PurchaseOrderDet.ExchangeRate, PurchaseOrderDet.UnitPrice, PurchaseOrderDet.Discount, SUM(PurchaseOrderDet.OrderQty) AS SumOfOrderQty,

[Code] ....

View 7 Replies View Related

Predict Product With Sex And Age Of Customer.

Sep 17, 2006

i have table:

customer(customerid, age,sex....)

orderdata(orderid, customerid,day)

orderdetails(orderid, productid, quantity)

products(productid, productname,...)

now, i want to show some product for customer when i now him age and sex.

e.ct: if he is a man and age =20 i show product : ball, pull, sport close....... if man is a woman , i show lips, babara, t_shirt, skirt....

if man is a chirdren, i will show joy, story for chidren....

how i create my mining model. and how i query for result in DTS

View 1 Replies View Related

Calculate Average Growth Rate

Apr 30, 2008

I've got a statistics table that I've been writing to for about 2 years now. Every saturday night, a size (in MB) snapshot of each DB file is taken and dumped into this table. I'm then emailed a copy for that week.

Now, I'm trying to figure out what the fastest growers are. Here's the table ddl

CREATE TABLE [dbo].[DBSizeStats] (
[statid] [int] IDENTITY (1, 1) NOT NULL ,
[LogDate] [datetime] NULL ,
[Server] [varchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[DBName] [varchar] (200) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[MDFName] [varchar] (200) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[MDFSize] [decimal](18, 0) NULL ,
[LDFName] [varchar] (200) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[LDFSize] [decimal](18, 0) NULL ,
[TotalSize] [decimal](18, 0) NULL
) ON [PRIMARY]
GO


What I'm trying to figure out is how to query the average monthly and yearly growth percentages per DB on the MDFSize column.

I'm usually pretty good at this sort of thing, but I just can't seem to wrap my head around how to solve this issue. I'm not having a very good math day.

what am I missing here?

View 10 Replies View Related

Transact SQL :: Calculate SUM Of 100 Of EDSUM Column For EDCOST Column

Aug 18, 2015

How I can calculate the 'SUM of 100' of EDSUM column for EDCOST column. Every EDCOST should have sum of 100 on the calculation of EDSUM. I just want to know which is the EDCOST which has <>sum of 100.

Create table #sum (ED numeric, EDCOST numeric, EDName char(6), EDSum numeric, EDCode char(2))
Insert into #sum values (121, 2000,'HLMO',98,'DT')
Insert into #sum values (122, 2000,'HLMT',2,'DT')
Insert into #sum values (123, 2001,'HLMO',100,'DT')
Insert into #sum values (124, 2002,'HLMD',97,'DT')

[Code] ...

Expeced Output:
ED EDCOST EDName EDSum EDCode
126 2003 HLMR   98 DT
130 2005 HLMR   98 DT

View 7 Replies View Related

Power Pivot :: Get Order First Date For A Specific Product And Customer?

Nov 18, 2015

I have a table with all my orders lines, I need to identify (DAX formula) for a specific customer which is the first order of a specific article (first date filtered for customer and article) and use this information to tag the order line for that article for the specific customer as "Newly Ordered article" if the order date = first order date or as "Reordered article" if the date on the specific order line is subsequent to the first order date.

I imagine I need to combine a Lookup date filtered for customer and article and use it with a IF formula.

Similar to this I would also like to define that if the first order for a product for the specific custumer is older then a certain date, then this would be defined as and historical customer for the specific article, if the first order on the article is more recent the a specific date, then this will be defined as "new customer for that article".

View 2 Replies View Related

Power Pivot :: First Sales Date By Customer For Specific Product Only

Dec 21, 2012

I have a sales order table that has customer, sales, product and sales date.  I am looking to return the first sales date by customer for a specific product.

SalesTable:

Customer
Product
Sales Date
Sales
First Bike Date

Jon
Bike
12/4/2011
 $10.00

[Code] ....

I would like to return the date of the first bike purchase date by each customer and repeat that date for each row and customer.  Can I use function to complete?  I have a datedim table as well related to the sales date.

View 3 Replies View Related

Transact SQL :: Calculate DateTime Column By Merging Values From Date Column And Only Time Part Of DateTime Column?

Aug 3, 2015

How can I calculate a DateTime column by merging values from a Date column and only the time part of a DateTime column?

View 5 Replies View Related

Transact SQL :: Calculate Third Column Using Second Column And Variable

Nov 23, 2015

create table #t
(
id int,
col1 decimal(18,2)
)
go

[Code] ...

-- I want to subtract @X and col1. But my variable @X must be reduced for each value in col1 for each next row until it reaches zero.

-- OUTPUT:

-- id col1 col2
--@X at starting point is 15000
-- 1 5000.00 0 --@X IS 10000 = 15000 - 5000(col1)
-- 2 1000.00 0 --@X IS 9000 = 10000 - 1000
-- 3 10000.00 1000.00 --@X IS 1000 = 9000 - 10000
-- 4 12000.00 12000.00
-- 5 300.00 300.00
-- 6 35000.00 35000.00

--in col2 i just put zero where col1 is substract from @X and continue for every subsequent order.
-- in 3 row value is 1000 becouse @X is that big (1000 left from col1)

View 13 Replies View Related

Transact SQL :: Get All Children Of A Product With Product ID In Result Set

Aug 30, 2015

I am using the code below to get all the children of a particular product and it is working fine. How to get the particular product's id in the select statement. for example, i need to show 891 in a separate column for all the records returned by the query below.

DECLARE @Hierarchy TABLE (Product_Id INT, Parent_Product_Id INT)
INSERT INTO @Hierarchy VALUES (123, 234)
INSERT INTO @Hierarchy VALUES (234, 456)
INSERT INTO @Hierarchy VALUES (456, 678)
INSERT INTO @Hierarchy VALUES (678, 891)
INSERT INTO @Hierarchy VALUES (891, NULL)

[Code] .....

View 3 Replies View Related

Analysis :: MDX To Calculate Maximum Gap In Sales For A Product?

Sep 30, 2015

I have a fact table which lists the last 12 month historical sales of a product,country,month combination so the table structure is like:

<month, productID, countryID, (month-3 sales), (month-4 sales).........,(month-14 sales)>

I need to write an MDX query which will return a flag that indicates if a product has a gap of more than 2 consecutive months in terms of positive sales. So I calculate if there is a gap of 3 months. If yes, then return 1 else null. The calculation below is scoped at product level.

IIF(([month-3 sales]<=0 AND [month-4 sales]<=0 AND [month-5 sales]<=0)
OR  ([month-4 sales]<=0 AND [month-5 sales]<=0 AND [month-6 sales]<=0)
OR ([month-5 sales]<=0 AND [month-6 sales]<=0 AND [month-7 sales]<=0)
...............
OR ([month-12 sales]<=0 AND [month-13 sales]<=0 AND [month-14 sales]<=0)),1,NULL)

Unfortunately I cannot do this calculation at relational level as a product may have a gap of more than 2 months at country level but may not have this at a higher level in geography.

optimizing this as the performance is bad and other calculated measures are dependent on this. Based on this calculation, I can write a scope which sums up all products so that I get the count of products with a gap of more than 2 months in sales.

I have also tried CASE statement and NESTED IIFs but the performance is worse than the above.

View 5 Replies View Related

Transact SQL :: Create A View For Getting Rate What Was There On Said Period

May 13, 2015

table1

id Rate start end
A01 2 01/04/2015 31/03/2016
A02 2 01/04/2015 31/03/2016
A03 2 01/04/2015 31/03/2016
A01 2.5 01/04/2016 31/03/2017
A02 2.5 01/04/2016 31/03/2017
A03 2.5 01/04/2016 31/03/2017

table2

id Received
A02 13/05/2015
A02 23/07/2016

View 3 Replies View Related

Summation Of Column Using Matrix Region

Feb 14, 2007

can anyone help me about reporting services on how to sum the coloumn and put it on a textbox... but the case is like this,

Stud Name Fee Name Fee Amt. Amt Paid
John Doe Registration 1,000 1,000
Tuition Fee 5,000 3,500
1,500
Jane Bake Tuition Fee 5,000 5,000

SubTotal 16,000 11,000


when i aggregate the Fee Amt. using Sum function i get the result of 16,000 because john doe break his payment in to two(it should be 11,000 only). any help would be appreciated.

Thanks...

View 1 Replies View Related

Transact SQL :: Find Last Transaction Of A Particular Type For Each Customer

Nov 12, 2015

I am working with SQL 2012 Express and I have a table with all transactions of invoices and payments for each customer. I am looking to find the last transaction detail of either two particular types of transactions (but not both) for each customer. So far I have tried various combinations around

SELECT        MAX([sbt::dte]) OVER (PARTITION BY [sbt::code]) AS LastPayment, [sbt::folio], [sbt::typ], [sbt::net] 
FROM dbo.tblSalbatTxn
WHERE      ([sbt::typ] = 13 OR [sbt::typ] = 17) 

Then there are some cases where customers have made more than the one of the same transaction type on that same last day which I would then like to sum the net value for that day of that transaction type.

I have also worked around this but it filtered the transaction type after it found the last transaction for each customer irrespective of it's transaction type.

SELECT        TOP (100) PERCENT a.[cl::code], a.[cl::alpha], b.[sbt::folio], b.[sbt::typ]
FROM            dbo.tblSalAccounts AS a INNER JOIN
                         dbo.tblSalbatTxn AS b ON a.[cl::code] = b.[sbt::code]
WHERE        (b.[sbt::dte] =
                             (SELECT        MAX([sbt::dte]) AS Expr1
                               FROM            dbo.tblSalbatTxn
                               WHERE        (b.[sbt::typ] = 11 OR
                                                         b.[sbt::typ] = 17) AND ([sbt::code] = b.[sbt::code]))) 

View 8 Replies View Related

Transact SQL :: Merge Two Rows Into One Based On Same Customer Number

Oct 26, 2015

I have a table Customer with below column

CustomerNumber , FName,LName,DOB

I have either 2 or 1 row for each customer number  I want to write a SQL to pull data into 1 table based on same CustomerNumber, if only one row is present for the particular customer number it should pull null in FName2,LName2,DOB2 columns.

example:
CustNumber  Fanme   Lname   DOB
1  Sam tiller 08/26/1981
1  Joe   timy  01/02/1986
2  jack  niks   09/09/1990

Result I want:
CustNumber Fname1  Lname1 DOB1 Fname2 Lname2 DOB2
1  Sam  Tiller 08/26/1981 Joe  timy 01/02/1986
2  Jack  niks  09/09/1990 null null null

View 7 Replies View Related

Show The Rows Containing Same Values Rate As Column In Html Table

Mar 27, 2008

Hi All,

I have following problem
please help me to resolve it.

There is table for shipping
as follows:




City


Kg


Rate(rs)




Rajkot


1


25.00




Rajkot


2


30.00




Rajkot


3


42.50




Ahemedabad


1


42.50




Ahemedabad


2


55.00




Ahemedabad


3


67.50




Ahemedabad


4


80.00




Goa


1


90.00




Goa


2


105.00




Goa


3


120.00




Gondal


1


25.00




Gondal


2


30.00




Gondal


3


42.50




Morbi


1


25.00




Morbi


2


30.00




Morbi


3


42.50




Gandhinagar


1


42.50




Gandhinagar


2


55.00




Gandhinagar


3


67.50




Gandhinagar


4


80.00




 We need to display
the table in html page using any Asp.Net language.

The result table should be:




City(s)


1


2


3


4




Rajkot,Gondal,Morbi


25.00


30.00


42.50


-




Ahemedabad,Gandhinagar


42.50


55.00


67.50


80.00




Goa


90.00


105.00


120.00


-




Baruch


70.25


80.00


92.00


120.50




 Description:

- Display all the cities
together for which all the shipping charges for (1-4) kgs are same. The range
of kgs is not fixed. 

Reply as soon as possible.

Thanks

View 3 Replies View Related

Transact SQL :: Finding Last Purchase Price For Each Product?

Sep 29, 2015

I need to find the last purchase price for each product.  If I run the following code, I correctly get 1 result for each productID and the last purchase order number.

SELECT pod.article as ProductID,max(pod.order_ID) as LastOrderfrom apodetail podgroup by pod.articleorder by pod.article

Now I need to add in the price for that product on that orderID.  I've tried the following self join query, tried it without the join, and tried adding DISTINCT, but they all return more than 1 row per ProductID.

SELECT pod.article as ProductID,max(pod.order_ID) as LastOrder,pod2.rev_price as UnitPricefrom apodetail podjoinapodetail pod2on (pod2.order_ID = pod.order_id)group by pod.article,pod2.rev_priceorder by pod.article

How can I get it to simply add the price to the first query?

View 10 Replies View Related

Transact SQL :: Get List Of Items Present In Order Based On Confidentiality Code Of Product

Sep 29, 2015

I want to get the list of items present in that order based on the confidentiality code of that product or Item and confidentiality code of the user.

I display the list of orders in first grid, by selecting the order in first grid I display the Items present in that order based on the confidentiality code of that item.

whenever order in 1st grid is selected i want to display the items that the item code should be less than or equal to the confidentiality code of the logged-in user other items should not display.

If the all the items present in the order having confidentiality code greater than Logged-in user at that time the order no# should not display in the first grid.

Table 1:Order

Order_Id Order_No Customer_Id

2401 1234567 23
2402 1246001 24
2403 1246002 25

Table 2 : OrderedItems

OrderItem_Id Order_Id Item_Id Sequence

1567 2401 1001 1
1568 2401 1003 2
1569 2402 1005 1
1570 2402 1007 2
1571 2403 1010 1

Table 3: ItemMaster

Item_Id Item_Name confidentCode

1001 Rice Null
1003 Wheet 7
1005 Badham Null
1007 Oil 6
1010 Pista 8

Out put for 1st grid 

**Note :** Logged-in user have confidentiality code 6

Order No Customer
1234567 23
1246001 24

3rd order is not displayed in the grid

After user selects the 1st order in the grid then the items present in that 1st order should be displayed as 

1001     Rice

the second item not displayed because that having confidentiality code greater than user.

After user selects the 2nd order in the grid then the items present in that order should displays

1005 Badham
1007 Oil

I need the query to display the order details in 1st grid.

View 3 Replies View Related

Transact SQL :: Calculate Events On Each Day

Jun 17, 2015

Need calculating the count of events on each day. I have an event log table as shown below. 

DECLARE @EventLog TABLE ( event_id int, status_id varchar(20) , dttm datetime )
INSERT INTO @EventLog
SELECT '100','Inplace','01/05/2015 05:00' UNION ALL
SELECT '100','Removed','03/05/2015 10:00' UNION ALL
SELECT '100','Inplace','05/05/2015 10:41' UNION ALL

[Code] ....

I need an output to look like on each day how many events were in place.

E.g.: for the month on May , Event_id 100 was inplace on 1st and removed on 3rd , so on 1st may 2 event_ids (100, 103) hence 2 . 

event_ids - 103 / 104 and inplace the whole month and not removed. so its calculated the count as 2 til towards teh end of the month. 

So I need to count of all each event_id in place for each day in may. 

How to calculate the missing dates to ...

View 7 Replies View Related

Transact SQL :: How To Calculate A Ratio

Oct 28, 2015

How do I author a SQL Query which meets the following requirement: Display a ratio of (instances where status is a success)/(instances where status is a success or instance is a failure). The below syntax is incorrect. However, I hope to beter explain what I am trying to accomplish using the incorrect SQL query below.

SELECT SUM(Case When Status = "SUCCESS")/SUM( Case When Status = "FALLBACK")
FROM ruleResults;

View 2 Replies View Related

Transact SQL :: How To Calculate A Running Stock Value

Oct 8, 2015

I have the following store procedure :

SELECT APHIST.ReturnDate AS ATDATE
,API_HIST.[ActionPlanItemID]
,API_HIST.[ActionPlanID]
,PIT.[ProductItemID]
,PIT.ProductItemCode
,PIT.Name,

[code]....

What I am trying to get is a RunningStock level column which is able to display stock level as describe below :

If ItemStatus value is 0, that means that the item has been taken out from stock.

So based on that the first row running Stock level is calclulated as

(ProductQuantity * ItemUnitWeight)-ItemQuantity=9...

For the second record, ItemsStatus=1 which means the item return to stock, at the time the running stock value calculation should be the previous row Running Stok value (=9 ) +(ItemQuantity*ItemUnitWeight)When the ItemStatus=2, that means the item is definitely out and will be never back to current stock. Is there a way to get that calculation field ?

View 6 Replies View Related

Transact SQL :: Calculate Total Between Two Columns?

Sep 16, 2015

I have table named #table and three columns. SinGroup(it does not matter, can be anything), Column1, and Column2.

CREATE TABLE #table(
sinGroup NVARCHAR(10)
,column1 INT
,column2 int
);

And i have some data:

INSERT INTO #table(sinGroup,column1,column2) VALUES
('y1',100,0),
('y2',0,60),
('y3',40,20),
('z1',150,0),
('z2',0,50),
('z3',0,50)

I want to know how to get this result set (c1 - c2 and group by Y and Z and the result shown under the column 1):

SinGroup C1 C2

y1 100 0
y2 0 60
y3 40 20
Y 60 0
z1 150 0
z2 0 50
z3 0 50

Z 50 0

And also result like this (c1-c2 and grop by each row,the result show under the column 1):

SinGroup C1 C2
y1 100 0
y1 100 0
y2 0 60
y2 -60 0
y3 40 20
y3 20 0
z1 150 0
z1 150 0
z2 0 50
z2 -50 0
z3 0 50
z3 -50 0

View 5 Replies View Related

Transact SQL :: Query To Calculate In Array Like Excel

Nov 4, 2015

I am trying to create a "Loan Ledger Card" in SSRS which does the calculation up to report extracting time. I was able to create it on Excel (Click to download the Excel file) as we can calculate amounts for each installment based on Row and Column name. You can test it by putting any amount (Here it should be below 62000 as it is the total balance of loan) in "Amount Paid" yellow cell and see the effect.

I have made a selection in SQL (attached query and result in screenshot). It calculates the total paid amount by now on the first row, and all due amounts in other rows. Basically, It should first deduct the interest from first row, then principle, same process for second row and so on until it covers the whole paid amount.

SELECT
'0' As RN
,memrepay.lnr
,'Repayment' AS Type
,SYSDATETIME() AS NOW
,SUM(memrepay.mprinc) As PrincPaid
,SUM(memrepay.mint) As IntPaid

[Code] .....

How can I do the similar calculation of Excel file in "SQL query" or "SSRS custom code"?

View 2 Replies View Related

Transact SQL :: Calculate Rolling Year Sales?

Aug 19, 2015

I have 2 tables as follows:

table A-NewParts
PartNumber
Description
LaunchDate
a123
product a
4/1/2009

[code].....

I want to get end result as sales for each new product for a rolling period from Launch date as year1 sales,year2 sales...and so on which I got through case statements.I am stuck on how to get the total Sales for all products (including new products) in the same rolling period based on the different launch dates for each new product.

PartNumber
Description
LaunchDate
Yr1 Sales
Total Yr1 Sales
Yr2 Sales
Total Yr2 Sales
a123

[code].....

View 3 Replies View Related

Transact SQL :: Calculate Size Of All Tables In A Database

Nov 16, 2015

I need to build a query to calculate the size of all tables in a database ...

View 5 Replies View Related

Transact SQL :: How To Calculate Size Of Files That Have UNC Paths For

Mar 27, 2014

I am on SQL Server 2008 R2. I have a table that contains a field called [Location]. In that field is a UNC path to the physical file on the repository. Is there a way in SQL Server that I can say give me the select sum([Location] UNC file) where criteria? I saw some posts about xp_filesize or xp_GetFileDetails, but I do not see them in master. I am unable to add anything and wondering if there is any native functionality that would allow me to accomplish this!?

View 4 Replies View Related

Transact SQL :: How To Calculate Number Of Employees In Each Month

Jun 17, 2015

I have a table which has name,Speciality,start date and end date. So each person may have 1/more rows .They will have more if they change their specialities. For example if you look at the data below.

AdjusterNameSpecialtyDatestartDateEnd
Test Inside Property2009-08-29 2010-07-31
Test Management2010-08-012012-07-31

If we see at the data above Test has 2 rows because he changed his specialty in the middle.My requirement is to calculate the total number of employees in each month for last 2 years in each speciality. For example if we look at the example above, Test was in Inside property from 2009 Aug to 2010 Aug but if i use just the date start and take the month for each adjuster it gives me the number of adjusters started in that year and month but what i want is Test should be counted in all the months for Inside property until 2010 07 month. Which means i want to have the total number of adjusters present by each speciality for each month of last 2 years .

View 2 Replies View Related

Transact SQL :: Efficient Way To Calculate Unique Values?

Jul 14, 2015

I have a data set as -

ID       Set Date          DB Date
100     Null                 07/01/15
100     07/05/15         07/02/15
100     07/10/15        07/08/15

I want to able to get 2 unique dates

1. 07/02/15 - As I want the DB date for ID - 100 when set date changed from a null value to non null value.

2. 07/08/15 - As I want the DB date for ID - 100 when a non null set date changes.

The table has such records for lot of different ID's.

View 29 Replies View Related

Transact SQL :: Calculate Average Based On A Scenario

Oct 30, 2015

Col1                      Col2       Col3          Col4
54763.00              21           0              0             
--Row1
59574.00              23           0              0             
--Row2
64085.00              20           0              0             
--Row3
0.0               0.00      0           0              0             
--Row4

I'm trying to calculate Average of Col1 of above table based on below scenario:

CASE WHEN all the columns in the above table are “0” (as highlighted) THEN I want AVERAGE of Col1 as (Row1+Row2+Row3)/3

ELSE if at least one of the column of highlighted row has value other than “0”, THEN I want the AVERAGE of Col1 to be (Row1+Row2+Row3+Row4)/4

View 7 Replies View Related







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