Transact SQL :: Repeating Customers Within A Timeframe
Oct 14, 2015
I'm trying to write a query which would bring back customers who are returning within a certain timeframe after their initial contact. Query 1 would be something like:
Select CustomerID, OrderID, StartDate, EndDate
FROM tblOrders
I would then like to bring back a recordset which showed any follow up orders within a timescale. Query 2:
Select CustomerID, OrderID, StartDate, EndDate
where EndDate is less than 6 months after Query1.EndDate
Joined by Query1.CustomerID = Query2.CustomerID
I haven't got as far as writing the T-SQL yet. I'm trying to think of a way to do it.
View 6 Replies
ADVERTISEMENT
Oct 6, 2011
I have a list of customers in my Customers table. What I am looking to do is to create QR codes for each customer in Reporting Services. I need to include the customer name, address, postcode, telephone number and contact name.
View 5 Replies
View Related
Oct 29, 2015
I am trying to pick up the customers invoiced twice or more within a month. In the case below Pepsi Cola and Jack Daniel were invoiced twice in October. The query need to pickup the previous month, se being in October I need to pick up the invoice of September.
create table #forum (Customer varchar(20),Invoiced date)
insert into #forum values ('Pepsi Cola','2015-09-01') ,('Pepsi Cola','2015-09-06') ,
('Pepsi Cola','2015-10-01') ,('Pepsi Cola','2015-10-02') ,('Pepsi Cola','2015-11-01') ,
('Ferrarelle','2015-09-01') ,('Ferrarelle','2015-10-01') ,('Ferrarelle','2015-11-16') ,('Ferrarelle','2015-11-01') ,
('Jack Daniel','2015-09-01') ,('Jack Daniel','2015-09-04') ,('Jack Daniel','2015-09-06') ,('Jack Daniel','2015-09-30') ,
('Jack Daniel','2015-10-01') ,('Jack Daniel','2015-10-18') ,('Jack Daniel','2015-11-01') ,
('Bud','2015-09-01') ,('Bud','2015-10-01') ,('Bud','2015-11-01')
select * from #forum
View 5 Replies
View Related
Dec 7, 2006
When is the Add-in going to be updated for the RTM of office?
View 1 Replies
View Related
Oct 6, 2006
My gut tells me this can't be done quite the way I'm hoping, but maybe someone has a little insight...
Is it possible to specify a specific timeframe for which triggers should be effective? I have some make-shift replication tasks which are currently done via pure insert/update queries and various times throughout the day. In the am our "target" table is completely wiped and repopulated from our "source" table which resides on a different server.
I'm hoping to setup update triggers throughout the day to catch changes to our "source" table. These triggers should only be active for a six-hour period throughout the day. Unfortunately true replication isn't an option here.
I can think of a couple ways to take care of this such as checking GETDATE() from the trigger itself and deciding whether or not to do anything, or perhaps scheduling a job to enable and disable triggers at the appropriate time. Is there a way to setup such a schedule for the trigger itself?
View 4 Replies
View Related
Nov 18, 2007
Hello Everyone,
I want to get a random value from a table only once a day, not on every page load.
With this SQL I can get a random value and everytime it gives me new value....
SELECT TOP 1 PRODUCTID
FROM PRODUCT
ORDER BY NEWID()
How the above query can be changed or there can be some sort of trigger set that same value for 24 hours....and it changes after that ?
View 5 Replies
View Related
Sep 7, 2014
I have a table with addresses and activity dates. I need to be able to retrieve the past 3 activity dates and see if the first and last occurred within 15 days. If so, I need to flag them.
Using max date gets me the last date but not the previous two. I was trying to use top 3 in desc order and that didnt seem to work either.
View 9 Replies
View Related
Oct 28, 2015
I have created ssrs report which has a parameter for start date. I want another parameter which shows time-frame of 6months,12 months,18 months,24 months which calculate dynamically from my start date
select distinct [dbo].[MSP_EpmResource_UserView].[ResourceName], [dbo].[MSP_EpmProject_UserView].[ProjectUID],[dbo].[MSP_EpmProject_UserView].[ProjectManagerName] ,
[dbo].[MSP_EpmTask_UserView].[TaskStartDate],[dbo].[MSP_EpmTask_UserView].[TaskFinishDate],
[dbo].[MSP_EpmTask_UserView].[TaskPercentCompleted],[dbo].[MSP_EpmProject_UserView].[Project Status] AS StatusForExecutiveReporting,
[Code] ....
View 4 Replies
View Related
Feb 27, 2008
I want to calculate how many number of people have got loans. In my report, there is one column called customerName. I can use count(CustomerName). But sometimes cutomers name appears twise or thrise. count(customerName) does not give the write nu of customers. How do I write T-SQL expression to get the rite no of customer?
Thanks
View 5 Replies
View Related
Apr 29, 2008
hi,
I have a person table with a field createdate and personid,
how can I display how many customers existed in the table by date.
eg.
1/4 200
2/4 250
3/4 256
4/4 280
regards,
amie
View 4 Replies
View Related
Sep 26, 2007
I am trying to link my ORDERS table to my CUSTOMERS table.
The Primary key in the CUSTOMERS table is a UNIQUEIDENT.
The foreign key it is linking to is an INT.
When I run a query in ACCESS, it says type mismatch....
Any solutions?
View 1 Replies
View Related
Nov 8, 2007
I€™m trying to group records that are in two collections and assign a Master Id. For example:
Example Base Table:
Collection Number Customer Id
--------------------------- -----------------------
3000001 244517
3000001 244518
3000002 244517
3000002 255519
3000002 244518
3000003 255520
3000004 266660
€¦
€¦
Since Customer Id 244517 is in collection 3000001 and 3000002 I want to group all customers in both collection and assign one master id. For example:
Example Results:
Collection Number Customer Id Master Id
--------------------------- ----------------------- --------------------------
3000001 244517 1
3000001 244518 1
3000002 244517 1
3000002 255519 1
3000002 244518 1
3000003 255520 2
3000004 266660 3
€¦
€¦
I€™m not sure how to perform this, can anyone direct me?
View 5 Replies
View Related
Dec 31, 2007
I deployed a clustering project. As a result, I got 10 clusters. Is there an automatic way to create a table with the customer ID and the cluster # that each customer was assigned to?
Thanks!
Ezes
View 4 Replies
View Related
Jan 22, 2007
I have a table with orders and customer info. I want to retrieve only customers with new orders only. These are the available fields: customer Id, Order Id, Order Date, and Order Subtotal. I need help with the "where" section of the query.
View 1 Replies
View Related
May 18, 2006
In Lesson1 of SSIS Tutorial, section "Running the Wizard to Create the Basic Package", is stated
"Specify the data source. You will use the Excel workbook, Customers.xls, as the data source..."
I have both AdventureWorks databases installed on my box as well as a host of samples but I can't find that file. Any pointers much appreciated.
TIA,
barker
View 12 Replies
View Related
Oct 4, 2000
Hi,
I'm trying to create a resultset with the top 100 customers for the year (based on this year's sales) and for each of these customers, to return 5 top items and their corresponding sales dollars, as well as percentage of total sales achieved by each item. What I'm struggling with is how to return specifically 5 sales items per customer. If I use a temp table or a correlated subquery, what is the exact syntax to use? Any advice will be appreciated. Thanks all :)
View 1 Replies
View Related
Feb 19, 2013
I have a large table that tells me customers and mailings (~4 million rows). So for each customer, I see what mailing(s) they received. It is at the mailing level so if a customer received 2 mailings, their will be 2 records for that customer number, one for each mailing they received. There are 3 different mailings.I am trying to calculate the count of customers that received all 3, as well as those that received 1&2 only, 1&3 only, and 2&3 only. For example:
CustNo Mailing
Tim 1
Tim 3
Dan 1
Dan 3
Jane 1
Max 1
Max 2
Max 3
Lauren 2
Lauren 3
Results:
All 3 - 1
1&2 only - 0
1&3 only - 2
2&3 only - 1
I have tried doing some funky table joining and EXISTS, but the query runs and runs because of how much data it has to sift through. Here is the code I am using to find Mailing 1&2 only customers, but I am not even sure it is getting me the right numbers. There are 2 different types of customers as well which is why I have custtype in there.
Code:
select a.custtype,count(distinct a.custno)
from myTable a
inner join (select distinct custno from mytable where [mailing]=2) b
on a.custno=b.custno
where a.[mailing]=1
and not exists(select * from myTable c where a.custno=c.custno and c.[mailing]=3)
group by a.custtype
View 14 Replies
View Related
Jul 23, 2005
Hello All,I do not know if this is the proper group to ask my question. Please dodirect me to the proper place.I have a database server and would like to store data for multiplegroups of customers. The data is not shared amongst the groups but areshared only amongst individuals composing a group.One solution would be to lump all data from all groups into a singleinstance of the database server accompanied with a tag that wouldidentify to which group each piece of information belongs.Is there a better method to achieve what I want to do. Would mysolution present any difficulties in the future in terms of performance,maintenance, scalability.Are there other solutions that may be available to address my needs.Any suggestions would be greatly appreciated.Thanks
View 3 Replies
View Related
Jul 17, 2015
I need to develop a process by which customers are notified that their 1) order was received and 2) order was shipped.
We are running Sql Server 2008 and all customers and data are located here on various servers. It is in a Windows 7 environment.Â
Has ever utilized Sql Server Database Mail for this purpose? Is it feasible?
View 6 Replies
View Related
Oct 18, 2006
I have an Access 2000 database which lists customers by name, and howmuch (in dollars) they have purchased of various products. How do Iwrite a SQL statement to select customers who make up the top 60% oftotal sales dollars? I need to have a list of customers returned.The list of customers that get returned will be used to select otherdata from the same database. (I mention this in case there are multipleways of getting the customer list).Thank you for any advice.
View 2 Replies
View Related
Jan 28, 2008
I have created an order form for my business. I placed a submit button at the bottom. I wanted all the clients information to go into my emailbox. Someone told me about MS SQL Server. I got excited and downloaded the 2005 Express version with all the trimmings. Now I am more confused than I was before. Someone please explain to me what I should do first. Redo the form with the studio then work with the server? I think I may have deleted something important from the server trying to figure it out. Help!!!!!!!!!!
View 7 Replies
View Related
Apr 26, 2006
Hi, I'm fairley new to SQL Server 2005. I've started to work with the tutorials to get a grip of it all... but when I'm running the wizard to create a packade I cannot find the folder Samples in the 90-folder... and the file Customers.xls is nowhere to find in any of the folders in MS SQL Server 2005 folder...
I downloaded and ran BOL from april2006 and also SP1 for SQL Server 2005...
Where can I find the right material to run the tutorials?
regards maggi
View 2 Replies
View Related
Oct 19, 2015
I am trying to write a RANKX Function as a calculated field instead of a measure, so I can used rank as a report filter but it is not working.I have customers that I can rank by sum of sales amount and then bucket their ranks within categories such as Top 10, 50, 100. The goal is then to use this Top Customers list as a filter on the Power BI report.So far I have the following as a calculated column.Â
=RANKX(CustomerTable,SUMX('CustomerTable',[Sales]))
View 2 Replies
View Related
Sep 14, 2006
Using the northwind database, how do I select the cutomerID of customers who havnt placed an order.
is it something like this?
select Customers.CustomerID
FROM Customers INNER JOIN Orders ON Customers.CustomerID <> Orders.CustomerID
and how can I display the customers who HAVE made orders alongside customers who havnt made orders.
Thanks in advance.
View 6 Replies
View Related
Jul 14, 2015
I am using a business management software application that uses SQL Server 2012 for data storage. The application is one that stores data about the customer, and then displays as requested. On certain customers, once saved, no save of future edits will work. Once the save button is clicked, there is a momentary hula hoop, followed by nothing. You have to cancel to get out, and then going back you see that the data was not saved. This only happens on certain customers (however, once the problem develops for a certain customer, it is consistent) and newly created customers seem to work fine. I am thinking that the software app is fine since the save process would be the same each time the button was clicked, so I am thinking its a database problem.
View 10 Replies
View Related
May 9, 2014
I have been looking for solution to automate the reports. I have many customers and many reports.each customer has their own will to receive individual report on specific day to their given/subscribed email addresses. So I have customer and report name and weekday, weekly, monthly (different schedules) and list of customers where each report is sent to.
Is there any way to implement this automation using simple T-SQL?
I have been able to make report in Crystal report and through command like (use TSQL) to generate report output in any format, lets say, .pdf and based on customer list send them email on their scheduled day.
I do not want to do this all in Crystal Report, because there is already SSRS we have but my question is, Ids there any easy way that i pass a command line to my sql server report and that returns me output so that i can send email to my clients?
View 3 Replies
View Related
Sep 22, 2014
What's the best way to calculate a customers age and value by month and year?
I need to be able to calculate customer value by month and year, and then to calculate their age at each month in time. I've found a way of grouping sales by month and year that includes age for a particular contact like this:
select fh.contact_number
, concat(year(fh.transaction_date), '-', month(fh.transaction_date)) as transaction_month_year
, cast(fh.transaction_date as date) as transaction_date
, sum(fh.amount) as ttl_amount_in_month
[Code] .....
It seems to work, but any better way to achieve this?
View 1 Replies
View Related
Sep 25, 2015
i need to generate documents for customers to sign automatically as sales staff enter their data into SQL. These are invoice style documents. I currently have word templates of the invoice documentation, i just need to be able to add the clients names, address etc into the relevant spaces for them to print off and sign.
I am good with TSQL and writing Stored Procs etc and can easily get the data ready - i just need to find a way to populate the templates in the right places and then save a copy for emailing.
View 9 Replies
View Related
Jan 26, 2007
All,
If this questions is misplaced please forgive me.
I have a customer who has a Win SBS 2003 Premium installation with a Win 2003 Standard member server running SQL 2000 housing a Practice Management App.
The new release of the Practice Management App only runs on SQL 2005.
My question is what are my options for obtaining SQL 2005 in the most cost effective way? The SBS Premium install was not a candidate for the 'free' upgrade to R2. Is there an 'upgrade' release of SQL 2005 for existing SBS Premium customers?
Any information would be greatly appreciated.
Thanks!
Ray
View 1 Replies
View Related
Nov 28, 2006
I can not seem to locate this file any where on my computer let alone in the specified directory. With out this file, it would be very difficult if not impossible to go through rest of the SSIS tutorials. Could I ftp this file from some locations so I could get started on the tutorials.
I would very much appreciate any help.
Thanks
View 2 Replies
View Related
Oct 23, 2007
I have a list that is grouped by Department inside it I have a table with two columns: name and hours. For example:
Department A
Name Houres
Mike 1
Department B
Name Houres
Mike 1
Steve 1
Department C
Name Houres
Mike 1
Steve 1
Outside the list I have another table that has a column for total hours for all departments:
Which in this case is 5. Everything work fine, but I have problem with displaying the total hours for all departments. In other words this will be my output
5
5
5
5
5
5
5
5
5
5
5
5
It will be repeated multiple times. I believe I have to add group to the table that contains the column (total hours for all departments.) but I can€™t do that b/c It is the total for all departments. Also I tried to hide duplicate wich works, but the problem with that when I export it to pdf it will print empty pages.
Any thoughts!
Thanks
View 1 Replies
View Related
Sep 14, 2007
we've seen the ease of calling sqlclr stored procedures whose parameters are known sql data types but are wondering what we're in for when we wish to pass .net objects to a sqlclr stored proc. We're confident that the sp's external assembly itself would build if instructed to "receive" .net objects etc, but can't envision how/if the sp's signature would generate nor can we imagine how such an sp would be called. We're not even sure we can envision how another sqlclr object (eg a trigger) would pass .net objects to the sp. Are we faced with using user defined data types if we need to pass .net objects to such sp's?
View 8 Replies
View Related
Jun 4, 2008
This is actually not asp.net, but I'm hoping someone can help me. I have a report that is pulling from a couple of different tables. I am trying to add a meal choice to the report. Let's say they have the option of choosing chicken, beef or fish. They check the checkbox next to the choice. My report is pulling the infor, but it is putting 3 rows for each person not taking into consideration what choice they chose. The checkbox's all write to the same column - ses. Here is the code for the stored procedure:
CREATE PROCEDURE [dbo].[spGetCourseEmailList1]( @Code1 char(9)) AS SELECT DISTINCT dbo.[names].lname as LastName, dbo.[names].fname as FirstName,dbo.[evser].ses as MealChoice,dbo.[evldg].paid as AmountPaid, dbo.[names].gp as PreferredAddress, dbo.[names].mi as MiddleInitial, dbo.[names].nname as NickName, dbo.[names].xname as Suffix, dbo.[names].hphone as HomePhone, dbo.[names].email as EmailAddress, dbo.[names].addr1 as HomeAddress1, dbo.[names].addr2 as HomeAddress2, dbo.[names].city as City, dbo.[names].st as State, dbo.[names].zip as ZipCode, dbo.[firms].fname1 as FirmName1, dbo.[firms].fname2 as FirmName2, dbo.[firms].faddr1 as FirmAddress1, dbo.[firms].faddr2 as FirmAddress2, dbo.[firms].fcity as FirmCity, dbo.[firms].fst as FirmState, dbo.[firms].fzip as FirmZip, dbo.[firms].fphone as FirmPhone, dbo.[names].udflist1 FROM dbo.[firms] INNER JOIN dbo.[names] ON dbo.[firms].firm = dbo.[names].firm
INNER JOIN dbo.evldgON dbo.[names].id = dbo.[evldg].id
INNER JOIN dbo.evregON dbo.[evldg].id = dbo.[evreg].id
Full OUTER JOIN dbo.evserON dbo.[evreg].code1 = dbo.[evser].code1
WHERE dbo.[evldg].code1 = @Code1 AND dbo.[evreg].code1 = @Code1 AND dbo.[evser].code1 = @Code1 AND dbo.[names].xwebflag <> 'Y'ORDER BY dbo.[names].lname, dbo.[names].fnameGO
The items in bold are what I added.
View 3 Replies
View Related