Hi,
I am in need of a query which would find the same customer coming in for three or more consecutive dates. To elaborate
I have a details table where I capture the following details
CustID, DateofPurchase, PurchaseDetails
I need a query to find how many customers have come in everyday consecutive day and count of the same for the a given period, say a month. Can anyone help me with a query for the same.
I have a fact -REVENUE table of accounts, each account can have multiple instances . And I have an Aggregate that summarize the latest occurrence of a revenue for each account ( in a chosen Period ) :
How can I find the percent of one of the lastest accounts Compared to all accounts? Assuming i have connect Dim_Time ( Y-Q-M-D ) to Revenue_Date, how can i find the percent of one Month Compared to all the months in the Quarter ( And so on hierarchies ) ?
I have a table full of service invoice records. Some of the invoices are continuous, meaning that there may be an invoice from 01-16-2015 through the end of that month, but then another invoice that starts on feb 1 and goes for 6 months.
I want to only pull the most recent. Keep in mind that there may be other invoices in the same table for a different period. An example might be:
If I want to return records where a column has similar data and occurs more than once what is the function?
Ex. If a database contains: Column 1 Column 2 Column 3 1 Dog White 2 Cat Brown 3 Dog Black 4 Mouse Black 5 Cat White
and I want to show all records where the 2nd column has more than one occurrences so that I get both records where Dog appeared and both records where Cat appeared (since each appeared more than 1 time) - what do i need to write as my function?
I have a column in a report with values Y or N or V. In the header, I have to show the number of times each value appeared.
I used RepeatingValue() with IIF() but it's counting all the values as same, e.g., if there are four occurrences of Y, two of N and one of V, I want something like this:
Y Cnt=4, N Cnt=2, V Cnt=1
My assumption was that this will work (white spaces added for readability:
=iif(
Fields!myCol.Value = "Y",
"Y Cnt=" & RunningValue(Fields!myCol.Value, Count, "dsMyDataSet"),
I have a table with below data. Requirement is to replace all integers with continuous 6 or more occurrences with 'x'. Less than 6 occurrences should not be replaced.
create table t1(name varchar (100)) GO INsert into t1 select '1234ABC123456XYZ1234567890ADS' GO INsert into t1 select 'cbv736456XYZ543534534545XLS' GO
I have a table as below: COMPUTERNAME, COUNTER, REASON WXP-13Failed WXP-1113Failed WXP-38Failed WXP-910Failed WXP-117Success
What I would like to do is create a percentage of Success vs. the Failed for the same Computername. Problem is when I use Group by I cannot tell the COUNTER of the Success anymore. This is what I have been using:
SELECT COMPUTERNAME, SUM(COUNTER) AS COUNTERTOTAL FROM ReturnTable GROUP BY COMPUTERNAME
Thank you. The above query actually targets a result table from another query, but that should not matter.
I want to retrieve staff who attend less than 80% for a meeting type assuming we have 10 meetings per list.
Meeting Table:
staffID list date ------------------------ 1 A 2013-01-15 2 B 2013-01-17 1 B 2013-01-17 1 A 2013-01-18 2 B 2013-01-19 1 A 2013-01-20 2 C 2013-01-21
* 1 - Dan * 2 - Jane
When the staffID occur 3 times (70%), query will Output:
staffName list Participation% ------------------------ Dan A 70
SELECT a.staffName, b.list, (100 - ((COUNT(c.staffID) * 100) / 10)) AS 'Participation%' from Staff AS a, listType AS b, Meeting AS c where a.staffID = c.staffID AND b.list = c.list GROUP BY a.staffName, b.list HAVING COUNT(c.staffID) > 2
WITH XMLNAMESPACES(DEFAULT 'urn:hl7-org:v3') SELECT t.document_id, t.person_id,pref.value('title[1]', 'varchar(255)') AS Title,
[Code] ....
This almost gives me what I need but I am only concerned with, in this case, the first sibling component but it is also picking up Information from the second. in this case it is picking up the caption containing "Strep A Antigen Scrn, Cult if Indicated (09/07/2015 6:35 PM EDT)" Also the number of components siblings change from document to document and although in this example I am trying to get the first component sibling, in actuality the component sibling is more towards the bottom.
Is there a way to only grab the info under the <title> in the component sibling I am after?
It will always be <title>Visit Diagnoses</title>. Is there a way to pinpoint this in the above query? Or am I going at it all wrong?
Finding numbers of occurrences of a string of characters in a column of TEXT datatype. DDL of involved table txt: create table txt (pk int, txtcol text) -- datatype of pk doesn't matter
declare @word varchar(80) set @word='help' declare @pk int, @count int, @i int, @dl int, @wl int set @wl=len(@word) declare abc cursor for select pk from txt where patindex('%'+@word+'%',txtcol)>0 order by pk open abc fetch next from abc into @pk while @@fetch_status=0 begin select @dl=datalength(txtcol) from txt where pk=@pk select @i=patindex('%'+@word+'%',txtcol)+@wl from txt where pk=@pk set @count=1 while @i<@dl begin select @count=@count+(len(substring(txtcol,@i,8000))- len(replace(substring(txtcol,@i,8000),@word,'')))/@wl from txt where pk=@pk set @i=@i+8001-@wl end select pk=@pk, occurrences=@count fetch next from abc into @pk end close abc deallocate abc pk occurrences ----------- ----------- 1 1
pk occurrences ----------- ----------- 2 2
pk occurrences ----------- ----------- 3 11 Edit: as suggested-reminded by jsmith8858.
I have a string of characters in my data flow and I need to add a derived column showing the # of times a certain character appears within that string. For example, my string in the data flow is:
NNNNNRJKSURNNNEJNNNN
Now I need to count the number of "N"s in that column. From the example above, I should get the integer 12, and that would be the value of my derived column. Any ideas?
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
As I just need the highest value returned I'm attempting to use MAX. However, the problem is that all values are being returned in the DaysOfWeek column as 5 even though they may range anywhere from 1-7. The DaysOfWeek should be for a unique EmployeeID/ReportID combination.
WITH sub AS( SELECT Shifts1.EmployeeID, X.*, Schedule.ReportID FROM ( SELECT CASE WHEN [M] = '1' THEN 1 ELSE 0 END +
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>
Does anyone know how many consecutive users can be logged into a MSSQL database? I have a database online and need to know how many users can be logged on at a time. someone told me 150 users and others say 200 and stillothers say it's unlimited based on licensing. I tried Microsoft's homepage but got nothing so please don't suggest it. (I spent two hours there)
Suppose that N users are executing the code, one independent of the other, in the same time and they both commit the transaction at the same time. Can I suppose that the rows inserted in the table by one user will be consecutive?
Hi,I'm trying to insert records from one table into another table. The destination table has a ROWID field which cannot be an identity key, but needs to 'act like' an identity key and have its value populated with (Max(ROWID) + 1) for each row added to the table.To my thinking, simply using (Max(ROWID) + 1) in my SELECT statement will not work as it will only be evaluated once so if I am adding 1000 records and Max(ROWID) is 1234, all 1000 entries will end up having a ROWID of 1235.Is there a way to accomplish this?Thanks
I work for a charitable organization, am new to this form (and sql programming) and trying to create a flag for unique records indicating the number of consecutive years a donor has given.
I have create a sample db idenifying donor, giving year and total pledges with multiple donor records existing for multiple years having donated.
INSERT INTO mygifts06 (Id,Gift_yr,Pledges) SELECT 155758,2005,15.00 UNION ALL SELECT 155759,2004,25.00 UNION ALL SELECT 155758,2004,40.00 UNION ALL SELECT 155757,2005,100.00 UNION ALL SELECT 155758,2002,30.00 UNION ALL SELECT 155758,2001,120.00 UNION ALL SELECT 155755,2003,15.00 UNION ALL SELECT 155758,2006,80.00 UNION ALL SELECT 155757,2003,65.00 UNION ALL SELECT 155759,2005,400.00
For the above dataset, I am trying to create the following output
I am using the following query (which works fine):
select min(timex) as start_date ,end_date ,entityid ,entityname ,locationid
[code]....
However I would like to not use the delta (it takes effort to calculate and populate it); instead I am wondering if there is any way to calculate it as part / whilst running the query.
Problem 2
I have the following table which shows the location of different people at 1 hour intervals
I'm trying extract a count of consecutive numbers, or "unbroken" years inthis case, at any particular given time.For example (simplified):CREATE TABLE #Customers(CustNo INT,YearNo INT,IsCust CHAR(1))INSERT INTO #Customers (custno, yearno, isCust) VALUES (999, 2006, 'Y')INSERT INTO #Customers (custno, yearno, isCust) VALUES (999, 2005, 'Y')INSERT INTO #Customers (custno, yearno, isCust) VALUES (999, 2004, 'Y')INSERT INTO #Customers (custno, yearno, isCust) VALUES (999, 2003, 'N')INSERT INTO #Customers (custno, yearno, isCust) VALUES (999, 2002, 'N')INSERT INTO #Customers (custno, yearno, isCust) VALUES (999, 2001, 'Y')INSERT INTO #Customers (custno, yearno, isCust) VALUES (999, 2000, 'Y')SELECT * FROM #CustomersCustNo YearNo IsCust----------- ----------- ------999 2006 Y999 2005 Y999 2004 Y999 2003 N999 2002 N999 2001 Y999 2000 YIn 2006 CustNo 999 would have been active for 3 years, 2004 for 1, 2001 for2, etc. Ideally I'd feed it a single year to lookupI'm resisting the urge to create cursor here -- anyone have any hints?....Chris.
Hello,Can someone please help me with a query?The table looks like this:BookedRooms===========CustomerID RoomID BookDateID1 1 200507011 1 200507021 1 200507031 1 200507091 1 200507101 1 200507111 1 20050712Desired result:CUSTOMER STAYS==============CustomerID RoomID ArriveDateID DepartDateID1 1 20050701 200507031 1 20050709 20050712Basically, this is for a hotel reservation system. Charges varynightly, and customer changes (shortening/extending stay, changingrooms, etc) happen quite often. Therefore, the entire stay is bookedas a series of nights.The length of the stay is never known, so it needs to be derived viathe Arrive and Depart Dates, based on the entries in the table.Notice, customers often stay in the same room, but with gaps between,so a simple MIN and MAX doesn't work. The output needs to showconsecutive nights grouped together, only.I've researched this quite a bit, but I just can't seem to make itwork.Any help would greatly be appreciated.Thanks!
Hi everyone, I'm hoping someone can help me with some sql statements. I have a temp table that contains 30 dates that a student has missed in the last year. I also have a holiday table of when training was not available. I want to find out if there are 6 consecutive days missed excluding weekends and holidays (from the holiday table). I know this is some nasty looping statement but I can't get my brain around it. I would like do this in a stored proc but I could use C# if necessary. Thanks in advance, Jessica
From individual event logs I have generated a table where arrivals and departures at a location are registered per device. As there are multiple registration points, there might be multiple consecutive registrations per location. If this is the case I need to filter those out and have one registration per location and in the result I need to get the earliest arrival and the latest departure of these consecutive rows.
So as long the field LocationID is the same in the next row, it needs to be grouped.
I have added the rows Grp1, Grp2, Grp in an attempt to get an unique grouping number with the following script in the select statement:
,ROW_NUMBER() OVER(PARTITION BY DeviceID ORDER BY logID) AS Grp1 ,ROW_NUMBER() OVER(PARTITION BY DeviceID, LocationID ORDER BY logID) AS Grp2 ,ROW_NUMBER() OVER(PARTITION BY DeviceID ORDER BY logID) - ROW_NUMBER() OVER(PARTITION BY DeviceID, LocationID ORDER BY logID) AS Grp
By subtracting Grp2 from Grp1 (Grp = Grp1 - Grp2) I hoped to get an unique group number for each set of equal consecutive locations, however the Grp2 column does not restart from 1 each time the LocationID changes: Grp2 in line 7 should have been 1 again, but it is 2 because this is the second row with LocationID = 3 in the list.
I am using the following query (which works fine):
select min(timex) as start_date ,end_date ,entityid ,entityname ,locationid
[code]....
However I would like to not use the delta (it takes effort to calculate and populate it); instead I am wondering if there is any way to calculate it as part / whilst running the query.
Problem 2:I have the following table which shows the location of different people at 1 hour intervals
I have a table with 3 columns: Item# | Date | ItemAmount. Everyday there is a number of transactions entered. An Item# can only be entered once par day (if it has occurred that day).
What I want to do is to : retrieve the number of total days where an Item has been entered for more than 2 consecutive days (for the month).
Example: if item I022 has been entered Monday and wed, then ignore, but if it's been entered Mon, Tues then return 2, if Mon, Tues, Wed then return 3 because the days are consecutive.
I have the following variables VehicleID, TransactDate, TransactTime, OdometerReading, TransactCity, TransactState.
VehicleID is the unique vehicle ID, OdometerReading is the Odometer Reading, and the others are information related to the transaction time and location of the fuel card (similar to a credit card).
The records will be first grouped and sorted by VehicleID, TransactDate, TransactTime and OdometerReading. Then all records where the Vehicle ID and TransactDate is same for consecutive rows, AND TransactCity or TransactState are different for consecutive rows should be printed.
I also would like to add two derived variables.
1. Miles will be a derived variable that is the difference between consecutive odometer readings for the same Vehicle ID.
2. TimeDiff will be the second derived variable that will categorize the time difference for a particular vehicle on the same day.
My report should look like:
VehID TrDt TrTime TimeDiff Odometer Miles TrCity TrState 1296 1/30/2008 08:22:42 0:00:00 18301 000 Omaha NE 1296 1/30/2008 15:22:46 7:00:04 18560 259 KEARNEY NE
Rajarajan writes "Kindly don't ignore this as regular case. This is peculiar. I need to delete one of duplicate records only if they occurs consecutively. eg.
1. 232 2. 232 3. 345 4. 567 5. 232
Here only the first record has to be delete. Kindly help me out.
Hi Fellows I am trying to organize these information.the data come form two tables that are not relating, but I did a join and my primary key is the filed polygon. I have a list of points(geomseq) for each polygon but the number of points(geomseq) can change. I have this inofrmation in a data base.