Summation Filter Problem
Feb 21, 2008
This is probably a simple problem for most but I'm a little confused on it.
I have a table containing shifts (ShiftStart (DateTime), NumHours (INT)). Now if I have a job scheduled to start at day S and run for X hours. I want to determine the day it would end on. I can do this using a cursor but am looking for a cursor-less solution if possible. Anybody have any thoughts.
Thanks,
~Justin
PS. Sorry this sounds like a math problem.
View 3 Replies
ADVERTISEMENT
Mar 28, 2008
How can I get the sum of the query results of these formula:
SELECT dbo.TechphonesCalibQA.ID, dbo.TechphonesCalibQA.EmpID, dbo.TechphonesCalibQA.EmpName, dbo.TechphonesCalibQA.[Level],
dbo.TechphonesCalibQA.Coach, dbo.TechphonesCalibQA.Queue, dbo.TechphonesCalibQA.PreferredName, dbo.TechphonesCalibQA.SesID,
dbo.TechphonesCalibQA.SesDate, dbo.TechphonesCalibQA.SesTime, dbo.TechphonesCalibQA.SesLen,
Case dbo.TechphonesCalibQA.G_Branded when dbo.TechphonesCalibClient.G_Branded then 1 else 0 end as G_Branded,
Case dbo.TechphonesCalibQA.G_PIVer when dbo.TechphonesCalibClient.G_PIVer then 1 else 0 end as G_PIVer,
Case dbo.TechphonesCalibQA.G_AskMemb when dbo.TechphonesCalibClient.G_AskMemb then 1 else 0 end as G_AskMemb,
Case dbo.TechphonesCalibQA.G_AskCall when dbo.TechphonesCalibClient.G_AskCall then 1 else 0 end as G_AskCall,
Case dbo.TechphonesCalibQA.G_UsedSend when dbo.TechphonesCalibClient.G_UsedSend then 1 else 0 end as G_UsedSend,
Case dbo.TechphonesCalibQA.V_Privacy when dbo.TechphonesCalibClient.V_Privacy then 1 else 0 end as V_Privacy,
Case dbo.TechphonesCalibQA.V_Followed when dbo.TechphonesCalibClient.V_Followed then 1 else 0 end as V_Followed,
Case dbo.TechphonesCalibQA.V_Changed when dbo.TechphonesCalibClient.V_Changed then 1 else 0 end as V_Changed,
Case dbo.TechphonesCalibQA.D_UseEffect when dbo.TechphonesCalibClient.D_UseEffect then 1 else 0 end as D_UseEffect,
Case dbo.TechphonesCalibQA.D_ConConfi when dbo.TechphonesCalibClient.D_ConConfi then 1 else 0 end as D_ConConfi,
Case dbo.TechphonesCalibQA.D_PropDoc when dbo.TechphonesCalibClient.D_PropDoc then 1 else 0 end as D_PropDoc,
Case dbo.TechphonesCalibQA.D_UseKb when dbo.TechphonesCalibClient.D_UseKb then 1 else 0 end as D_UseKb,
Case dbo.TechphonesCalibQA.S_Fix when dbo.TechphonesCalibClient.S_Fix then 1 else 0 end as S_Fix,
Case dbo.TechphonesCalibQA.S_Recorded when dbo.TechphonesCalibClient.S_Recorded then 1 else 0 end as S_Recorded,
Case dbo.TechphonesCalibQA.S_Provided when dbo.TechphonesCalibClient.S_Provided then 1 else 0 end as S_Provided,
Case dbo.TechphonesCalibQA.C_Askaddit when dbo.TechphonesCalibClient.C_Askaddit then 1 else 0 end as C_Askaddit,
Case dbo.TechphonesCalibQA.C_Stated when dbo.TechphonesCalibClient.C_Stated then 1 else 0 end as C_Stated,
Case dbo.TechphonesCalibQA.AB_PresntInfo when dbo.TechphonesCalibClient.AB_PresntInfo then 1 else 0 end as AB_PresntInfo,
Case dbo.TechphonesCalibQA.AB_ResMbrTym when dbo.TechphonesCalibClient.AB_ResMbrTym then 1 else 0 end as AB_ResMbrTym,
Case dbo.TechphonesCalibQA.AB_Respond when dbo.TechphonesCalibClient.AB_Respond then 1 else 0 end as AB_Respond,
Case dbo.TechphonesCalibQA.AB_Appsol when dbo.TechphonesCalibClient.AB_Appsol then 1 else 0 end as AB_Appsol,
Case dbo.TechphonesCalibQA.AB_Adjustsp when dbo.TechphonesCalibClient.AB_Adjustsp then 1 else 0 end as AB_Adjustsp,
Case dbo.TechphonesCalibQA.AB_respect when dbo.TechphonesCalibClient.AB_respect then 1 else 0 end as AB_respect,
Case dbo.TechphonesCalibQA.AB_MuteOcur when dbo.TechphonesCalibClient.AB_MuteOcur then 1 else 0 end as AB_MuteOcur,
Case dbo.TechphonesCalibQA.AB_HoldOcur when dbo.TechphonesCalibClient.AB_HoldOcur then 1 else 0 end as AB_HoldOcur,
Case dbo.TechphonesCalibQA.SS_actlist when dbo.TechphonesCalibClient.SS_actlist then 1 else 0 end as SS_actlist,
Case dbo.TechphonesCalibQA.SS_empathy when dbo.TechphonesCalibClient.SS_empathy then 1 else 0 end as SS_empathy,
Case dbo.TechphonesCalibQA.SS_focus when dbo.TechphonesCalibClient.SS_focus then 1 else 0 end as SS_focus,
Case dbo.TechphonesCalibQA.SS_confi when dbo.TechphonesCalibClient.SS_confi then 1 else 0 end as SS_confi,
Case dbo.TechphonesCalibQA.SS_commun when dbo.TechphonesCalibClient.SS_commun then 1 else 0 end as SS_commun,
Case dbo.TechphonesCalibQA.SS_accent when dbo.TechphonesCalibClient.SS_accent then 1 else 0 end as SS_accent
FROM dbo.TechPhonesCalibClient INNER JOIN
dbo.TechphonesCalibQA ON dbo.TechPhonesCalibClient.SesID = dbo.TechphonesCalibQA.SesID
View 10 Replies
View Related
May 23, 2002
I have 2 tables ZIPCROSS and HOUSEHOLDS. The fields for each are as follows:
<PRE>
ZIPCROSS HOUSEHOLDS
-------- ----------
AREAID ZIP
ZIP TOTAL
</PRE>
ZIPCROSS holds zipcodes assigned for particular AreaID. HOUSEHOLDS contains TOTAL number of household in each zipcode.
Now, I need to build a query that returns SUM of TOTAL for a given AREAID grouped by SCF (first 3 numbers of the zipcode) and SUM of TOTAL for a given SCF. Thus the results should look something like this:
<PRE>
AREAID SCF TOTAL SCFTOTAL
------ --- ------- ---------
1 900 1234 43210
1 901 2345 54321
</PRE>
etc... I can write a query that can get the right TOTAL or the right SCFTOTAL but not both on one query. The following query gives me the right SCFTOTAL but not TOTAL.
SELECT A.AREAID, LEFT(C.ZIP,3) AS SCF, SUM(D.TOTAL) AS TOTAL, SUM(E.TOTAL) AS SCFTOTAL
FROM AREAORDER A JOIN ZIPCROSS C ON A.AREAID=C.AREAID
JOIN HOUSEHOLDDATA D ON C.ZIP=D.ZIP
JOIN HOUSEHOLDDATA E ON LEFT(C.ZIP,3)=LEFT(E.ZIP,3)
WHERE A.MAILINGORDERID=133
GROUP BY A.AREAID, LEFT(C.ZIP,3)
ORDER BY A.AREAID, SCF
I'm aware of why this doesn't work but I can't seem to find the right approach. Any solutions? TIA.
View 1 Replies
View Related
Oct 9, 2006
I have some data -- counts ID'd by location and grid East like this --Loc East NCA 100 3CA 103 5CA 109 2CA 110 3I'm interested in the total of N on either side of the largest gap inEastings.In this case the largest gap is 6 (between 103 and 109), and the sum ofN for the 2 rows below the gap is 8, and for the 2 above the gap it's5.The problem is to locate the largest gap, and compute the sum of N forthe cases on either side. There are multiple locations, multipleEastingsper location, but only one largest gap. (If there are two largestgaps, itdoes't matter which one is used for the sums.)I can do this with multiple passes -- first locate the largest gap,then goback and locate the Eastings on either side, then sum up the Ns.That'srealy clumsy, I can't figure out how to do it more quickly, and I'm notsurewhat I'm doing is right. Any help would be appreciated.Thanks,Jim Geissman
View 2 Replies
View Related
Jul 26, 2006
Dear all,
I am attempting to do a simple summation statistics calculation with T-SQL to count rows based on an int column FK relationship to another table.
I have two tables: (1) document, and (2) filespec. Both tables have an int primary key column and some miscellaneous columns. Filespec has an int field which is keyed to the primary key of document (FK constraint), thus, each document can have zero-to-many file specifications.
Example:
Document Table:
DocID Name
1 Approved Plan
2 Photo Gallery
Filespec Table:
FileID DocumentID Name
1 2 First Photo
2 2 Second Photo
Expected Result:
DocID FileCount
1 0
2 2
How to generate this result? Thanks in advance for advice.
View 5 Replies
View Related
Apr 30, 2007
I have been toiling over getting this query to run properly for a while now and finally had to turn to the community for help. We are trying to develop a query that will show us an idea of customer loyalty at the store. It basically takes the transactions for a specific user from one table, and matches that customer ID to the customer table so we can also select names and phone numbers. The query runs great, but it shows every single transaction that a customer has done between our specified time range. We want to be able to have the query add each transaction and total it for us so we have just one customerID with one total instead of say one customerID with 19 transactions. Any ideas? Our current query is below:
select customer.accountnumber, customer.firstname, customer.lastname,
xaction_total
From Customer, xaction
where xaction_time between '01/1/2006' and '12/31/2006'
and Customer.ID = xaction.CustomerID
and customer.accountnumber not like 'X%'
order by customer.accountnumber desc
View 2 Replies
View Related
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
Mar 24, 2008
Hi allI need to perform a summation on a column of a table based on acriteria given in another column in the same table. The catch is ineed to perform different sums according to the number of criterias inthe criteria column, in a single query. the structure of the table issomethinmg like this (only relevant columns are shown)TABLE1Value - numeric(20,6)Month - intindicator - bitNow i need to do something like:SELECT Month, SUM(Value) FROM TABLE1WHERE indicator = 1GROUP BY Monthand alsoSELECT Month, SUM(Value) FROM TABLE1WHERE indicator = 0GROUP BY MonthHow can i do this in a single query, something like this:SELECT Month, SUM(Value where indicator=1), SUM(Value whereindicator=0) and so on .......Could any body please help me on this ?
View 25 Replies
View Related
Aug 27, 2005
Hello All:
I am not sure if I wrote the question's title appropriatly or not.....but anyways I wud try to explain the problem.
I am facing a problem solving the following task in MS Access (I believe it can surely be solved in access or SQL server).I am posting a sample table format here for reference and also postin the expected result table there-after.
The problem goes like this.(Read Carefully)
I have a table which contains a payment history with one row per account (each account number is unique) and related payment history for each account.
Sample Table:
AcctNo Dt1 P1 Dt2 P2 Dt3 P3 Dt4 P4 .........
------------------------------------------------------------------------------------------------------------
101 | 11/07/2002 | 10.00 | 11/07/2002 | 20.00 | 01/17/2003 | 120.00 | 01/25/2003 | 20.00
201 | 10/28/2003 | 30.00 | 10/28/2003 | 25.00 | 03/22/2004 | 130.00 | 03/22/2004 | 75.00
301 | 04/07/2005 | 40.00 | 04/23/2005 | 25.00 | 01/07/2001 | 140.00 | 01/07/2001 | 65.00
401 | 01/13/1999 | 50.00 | 01/13/1999 | 35.00 | 10/29/2002 | 150.00 | 10/17/2002 | 55.00
501 | 05/23/2001 | 60.00 | 05/02/2001 | 45.00 | 02/13/2000 | 160.00 | 02/13/2000 | 25.00
601 | 09/17/1998 | 70.00 | 09/15/1998 | 55.00 | 07/07/1998 | 170.00 | 07/07/1998 | 15.00
701 | 12/11/2000 | 80.00 | 12/29/2000 | 65.00 | 11/27/1999 | 180.00 | 11/28/1999 | 15.00
where Dt is date and P1/2/3/... is payment.There cud be 1 or more than 1 payments in a particular month as shown.
The original file has more than 200 columns for the payment i.e till Dt200,P200
I need to see aggregated monthly payment history for all accounts. i.e. a table for all accounts with related payments for each month (its OK if a day vary in particular month...consolidation shud be monthly) starting from the earliest to the latest possible.
Result:-
Acct Month Pay Month Pay ...........
----------------------------------------------------
101 | 11/2002 | 30.00 | 01/2003 | 140.00 ...........
201 | 10/2003 | 55.00 | 03/2004 | 205.00 ...........
301 | 04/2005 | 65.00 | 01/2001 | 205.00 ...........
401 | 01/1999 | 85.00 | 10/2002 | 205.00 ...........
501 | 05/2001 |105.00 | 02/2000 | 185.00 ...........
601 | 09/1998 |125.00 | 07/1998 | 185.00 ...........
701 | 12/2000 |145.00 | 11/1999 | 195.00 ...........
I hope I have tried to explain the problem in as much detail as possible.
Please help me with your valuable solutions to the above task ASAP.If u want i can also send in as attachment the original file i am workin at to ur email id
Thanks
View 1 Replies
View Related
May 24, 2013
I am trying to update a parent table with a summation of its child records. The child records are being deleted because the transaction has become invalid because payment was made with a bad check or there was a posting error. So a rollback of sorts is required.
Here are is the DDL for the tables and DML for the data:
Code:
DECLARE @t1 TABLE
(
[Year] int NOT NULL,
[Parcel] varchar(13) NOT NULL,
[InterestDateTime] datetime NULL,
[Principal] decimal(12, 2) NULL,
[Penalty] decimal(12, 2) NULL,
[Code] ....
I tried to use a Merge statement with an ON MATCH for each TransType, but it complained that I could not have multiple update statements. OK. So I tried a MERGE with single update statement with a case and it complained that I was updating the same parent multiple times, which I was and want to! So, I tried the following update statement and it still does not work, though no error message.
Code:
update t1 set
t1.Principal = t1.Principal + (case when t2.TransType = 'R' then t2.Payment else 0 end),
t1.Penalty = t1.Penalty + (case when t2.TransType = 'P' then t2.Payment else 0 end),
t1.Interest = t1.Interest + (case when t2.TransType = 'I' then t2.Payment else 0 end)
from @t1 t1
inner join @t2 t2 on t2.YEAR = t1.YEAR and t2.Parcel = t1.Parcel
I am expecting the following after the update:
Code:
Select * from @t1
201200000018092013-03-14 00:00:00.000 211.15 10.00 3.14
201100000018092013-03-14 00:00:00.000 206.12 10.00 18.20
201000000018092013-03-14 00:00:00.000 219.41 10.00 35.37
200900000018092013-03-14 00:00:00.000 0.00 0.00 0.00
2012000001808X2013-03-14 00:00:00.000 9.65 0.00 0.06
2011000001808X2013-03-14 00:00:00.000 378.70 10.00 32.73
2010000001808X2013-03-14 00:00:00.000 0.00 0.00 0.00
2009000001808X2013-03-14 00:00:00.000 341.96 3.00 142.74
All I am getting are the original values.
View 14 Replies
View Related
Apr 15, 2008
Hello,
Here is my problem:
I use SQL Server 2005. I have approx. 50 tables in my database and 30 of them have a filed named "CompanyID". Example:
create table A (ID int identity, NAME varchar(100), COMPANYID int)create table A (ID int identity, REF_ID int, FIELD1 varchar(100), FIELD2 varchar(100), COMPANYID int)
Also there are nearly 200 stored procedures that read data from these tables. Example:
create procedure ABCasbegin /* some checks and expressions here ... */ select ... from A inner join B on (A.ID = B.REF_ID) where ... /* ... */end;
All my queries in the Stored procedure does not filter the tables by CompanyID, so they process the entire data.
However, now we have a requirement to separate the data for each company. That means that we have to put a filter by CompanyID to each of those 20 tables in each query where the tables appear.
Firstly, I put the CompanyID in the context so now its value is accessible through the context_info() function. Thus I do not need now to pass it as a parameter to the stored procedures.
However, I don't know what is the easiest and fastest way to filter the tables. Example:
I modified the above mentioned procedure in the following way:
create procedure ABCasbegin /* some checks and expressions here ... */
-- gets the CompanyID from the context: DECLARE @CompanyID int; SELECT @CompanyID = CONVERT(float, CONVERT(varchar(128), context_info()))
select ... from A inner join B on (A.ID = B.REF_ID) where ...
and A.COMPANYID = @CompanyID and B.COMPANYID = @CompanyID /* ... */end;
Now I have the desired filter by CompanyID. However, modifying over 200 stored procedures is rather tedious work and I don't think that this is the best approach. Is there any functionality in SQL Server that can provide the possibility to put an automatic filter to the tables.
For example: when I wrote "SELECT * FROM A", the actual statements to be executed would be "SELECT * FROM A WHERE CompanyID = CONVERT(float, CONVERT(varchar(128), context_info()))".
I was looking for something like "INSTEAD OF SELECT" triggers but I didn't manage to find any answer.
I would very grateful is someone suggests a solution for something like "global table filter" (that will help me make an easy refactoring)?
Thanks in advance.
Best regards,
Beroetz
View 5 Replies
View Related
Jan 26, 2006
Howdy,
I have a table that has a group. In this group, I want to filter by 2 different expressions, concatenated with an OR. BUT I can't change the "And/Or" column value for the first entry because it is grayed out. The column will automatically change to an OR value if both my expression column fields are the same (which I don€™t want) but if I put any other value in to the expression field of the second row, the "And/Or" field of the first row automatically changes to an AND.
PLEASE! How do I get the And/Or field "ungrayed" so I can change it to what I want?
The 2 filters I and using check the UserID = to the user, and the other is checking a count to get the Top N 1. (So just showing the current user and the top producer)
View 14 Replies
View Related
Feb 3, 2007
Hello I am working in an advertising company and I have to find all records who have advertised 7 days back but if one person has advertised more than once means for different products, his name should come only once. How can I filter this. I am totally new to this language I can write simple query but don’t know how to filter it.
Name IndividualID Product Date
A 1 x 2007-01-27.23.59.59.777
A 1 y 2007-01-28.00.00.00.000
b 2 xx 2007-01-28.00.00.00.000
A 1 z 2007-01-28.00.00.00.000
b 2 yy 2007-01-28.00.00.00.000
A 1 p 2007-01-28.00.00.00.000
c 3 m 2007-01-28.00.00.00.000
d 1 n 2007-01-28.00.00.00.000
A 1 s 2007-01-28.00.00.00.000
View 1 Replies
View Related
May 17, 2007
Hi,
I have a supllier named K O'Neill and i want to filter on his name in my supplier table . Is this possible ?
When I try Vend Name = 'K O%Neill' it does not work.
Can anyone help?
Thanks.
View 6 Replies
View Related
Aug 21, 2006
I need a query that returns every n record from the database and the last record.
For every n-th is easy, but I need a
WHERE Index % n = 0
but I need a last one too.
Any Help.
View 3 Replies
View Related
May 24, 2007
Hi I am wandering if it is possible to achieve the following:
I am using Reporting Services and Reporting services I got a report with a text parameter.
I would like the user to introduce AA and find the product AA and when he introduces AA* it finds AA, AAD, AAC...
I am doing the following:
Filter([DIM Product].[Product].ALLMEMBERS,
,IIF(INSTR(@Product, "*") > 0
,[DIM Product].[Product].currentmember.name = Replace(@Product, "%", "")
,INSTR([DIM Product].[Product].currentmember.name, @Product)
)
)
The problem ist that the function Replace does not work!
Does someone know how to do it?
View 1 Replies
View Related
May 22, 2007
What is the syntax for using IN as a filter? in SQL it would be IN( 'A', 'B', 'C') but this does not work in Reporting services.
View 4 Replies
View Related
Jun 9, 2008
In a SQLDataSource, the following line throws an error as an undefined function. FilterExpression='left$(lname,1) = "D"'
Isn't this a standard VB function and why does it produce an error. How do I fix?
Thanks
View 2 Replies
View Related
Jun 8, 2006
Hi,
I am new in framework 2 and I can't find a way to filter the sqldatasource.
I have an sqldatasource control that retrive data from data base-"Select * from myTable"
I set the fiterExpression property-sqlDataSource1.FilterExpression="ID='" + strID + "' " ;
I don't know how to continue from here.If I bound the sqlDataSource1 to a control like gridView it works good and I see the filter oparation. but I want to get the result set in the code and loop threw it like I did with ver 1.1 with sqldataReader:
While sqlDatareader1.Read { myCode ... }
How can I do it with sqlDataSource ?
Thanks,
David
View 4 Replies
View Related
Aug 24, 1999
I have two tables A and B. I want to insert data into tables C and D based on join between A and B (A.column = B.column). What is the best way to accomplish this type of task?
IE-------> If column = xyz then insert into table C
IF column = abc then insert into table D
ELSE do_not_insert
Please help.
Regards
Ziggy
View 1 Replies
View Related
Sep 15, 2004
I have been running traces in SQL Profiler and have not been able to get the filtering to work correctly. I am interested in capturing only statements that use CPU and have setup the filter for CPU > 0. It still returns all of the rows that have Null. Is there any way of filtering out the rows that have nunll for CPU?
Thanks,
Ken Nicholson
View 2 Replies
View Related
May 3, 2006
I'm an MDX newbie.. with some help I was able to create a query that returns accurate results. All I need to do now is filter for Completed Work value of greater than 0.
I have tried to use the filter wizard in VS2005, but I have never gotten the desired results.
Platform Info:
SQL Server 2005 Standard
VS2005
---------Start Statement----------------------------------------------------------
WITH
MEMBER [Measures].[Completed Work by WI on dt1] AS
(
[Assigned To].[Person].CurrentMember,
[Work Item].[System_Id].CurrentMember,
[Date].[Year Week Date].[Date].&[2006-04-23T00:00:00],
[Measures].[Microsoft_VSTS_Scheduling_CompletedWork]
)
MEMBER [Measures].[Completed Work by WI on dt2] AS
(
[Assigned To].[Person].CurrentMember,
[Work Item].[System_Id].CurrentMember,
[Date].[Year Week Date].[Date].&[2006-04-29T00:00:00],
[Measures].[Microsoft_VSTS_Scheduling_CompletedWork]
)
MEMBER [Measures].[Completed Work] AS
[Measures].[Completed Work by WI on dt2] - [Measures].[Completed Work by WI on dt1]
SELECT
NON empty
{
[Measures].[Completed Work]
}
ON COLUMNS,
NON EMPTY
{
([Assigned To].[Person].[Person],[Work Item].[System_Id].[System_Id],[Work Item].[System_Title].[System_Title])
}
ON ROWS
FROM
[Team System]
----------End Statement---------------------------------------------------
View 1 Replies
View Related
Jun 9, 2004
I got a field called Date#, datatype = datetime, default value = getdate().
So after i insert a record, the Date# will auto record the system date and the time. And my MS SQL Server show: 6/9/2004 12:24:35 PM
However i am not able to filter my record by date. The statement i tried are:
SELECT * from mytable WHERE Date# = '6/9/2004 12:24:35 PM'
SELECT * from mytable WHERE Date# = "6/9/2004 12:24:35 PM"
SELECT * from mytable WHERE Date# = 6/9/2004 12:24:35 PM
SELECT * from mytable WHERE Date# = '6/9/2004'
Pls help me,
Thanks a million
View 13 Replies
View Related
Dec 27, 2005
HI all friends
I have a Fact table like this
DIMENSSIONSMEASURES
------------------------------
idempidprodcutsalessalesws
I just want make the next query with MDX
SELECT sales
FROM myFactTable
WHERE salesws > 0
Note that salesws is a measure not a dimmension
How it would be in MDX? I need a lot of help
Regards!
View 4 Replies
View Related
Feb 6, 2006
Hi,
I need to filter my table to return data between 18:30 and 7:00
I am not sure how to do the half hour and span over midnight.
I think this might work for 18:00 and 7:00.
SELECT *
FROM MyTable
WHERE datePart(hour, Timestamp) Between 18 AND 24 Or datePart(hour, Timestamp) Between 00 AND 7
I would appreciate any help!
Thanks
View 5 Replies
View Related
Mar 15, 2008
I have a table with a varchar in it.
Inside the var char it contains data like:
Variable.[32] + Variable.[432] * (Variable.[333] / Const.[21])
What I am trying to do is search for all records that are using variable 333
I was trying:
SELECT * FROM my_table WHERE data_field LIKE '%Variable.[333]%'
However, that returning nothing.
I am going to guess that the [ ] need to be escape or something, but I don't know if thats really the issue.
Doing:
SELECT * FROM my_table WHERE data_field LIKE '%Variable%'
Works.
Thanks in advance,
Rich
View 2 Replies
View Related
Apr 14, 2008
I have an sql script that has 2 main blocks of Where filter which I'd call as Filter1 and Filter2 as follows:
Select
DisplayColumns...
From
InterestingTables
Where
(Filter1) --W1
AND --W2
NOT --W3
(Filter2) --W4
Note that Filter1 and Filter2 are composite filters (inner filters nested; it shouldn't matter as long as I have the outer parenthesis as above, right?).
Now, say SetF1ExF2 is the result set of the sql script above.
Additionally, let's say I obtain the result set SetF1 by having W2 to W4 commented out and SetF1AndF2 comes from commenting out W3.
Shouldn't the following hold: SetF1AndF2 = SetF1 - SetF1ExF2
I am having a discrepancy between the values with SetF1AndF2 < SetF1 - SetF1ExF2.
TIA.
View 1 Replies
View Related
Feb 17, 2012
I've got an MDX query I need to modify, but not quite sure how to proceed. I essentially know most of tye syntax, but am at a loss as to where the components of the syntax should appear in the query. Here is the original query:
Code:
WITH
MEMBER [Employee].[FTE vs FL].[CF Total] AS AGGREGATE([Client Facing Disciplines])
MEMBER [Time].[Year - Half Year - Quarter - Month - Date].[Trailing 12 Months] AS AGGREGATE(LASTPERIODS(60, STRTOMEMBER(@SelectedMonthEx, CONSTRAINED)))
MEMBER [Time].[Year - Half Year - Quarter - Month - Date].[YTD] AS AGGREGATE(YTD(STRTOMEMBER(@SelectedMonthEx, CONSTRAINED)))
[Code] ....
This is how I'm sure the two lines that say what should be excluded, I'm just not sure where they should go. I believe a FILTER statement is what I need, but not sure how to format it.
[Employee].[FTE vs FL].[Discipline].&[LOYALTY],
[Employee].[FTE vs FL].[Discipline].[Department].&[OLSON PR Chicago]
MDX is definitely not my strong point.
View 4 Replies
View Related
Apr 3, 2008
Hi ,
account_desc_out,Analysis_Desc_out,Sub_Analysis_Desc_out,debit_out,
credit_out,sub_Analysis_Code_out,Analysis_Code_out
-----------------------------------------------
11066-0001-01 GEN 6633 0.00000000 160.000000006633GEN
11066-0001-01 GEN 6633 160.00000000 0.000000006633GEN
When i run the below query the o/p is comming as above:actually no record should come bcz debit amt and credit amt should knock off .can anyone correct the below query:
select
account_code_desc as'Account_Desc_out',
analysis_code_Desc as'Analysis_Desc_out',
subanalysis_code_desc as 'Sub_Analysis_Desc_out',
case when drcr_flag='dr' then sum(isnull(base_amount,0)) else 0.00 end as 'debit_out',
case when drcr_flag='cr' then sum(isnull(base_amount,0)) else 0.00 end as 'credit_out',
subanalysis_code as 'sub_Analysis_Code_out',
analysis_code as 'Analysis_Code_out'
from Analysis_stg_tb as stg with (NOLOCK)
where subanalysis_code_desc='6633-Goverdhan S'
group by subanalysis_code,analysis_code,
account_code_desc,analysis_code_desc,subanalysis_code_desc,drcr_flag
having sum(case when drcr_flag='cr' then isnull(base_amount,0) else 0.00 end) -
sum(case when drcr_flag='dr' then isnull(base_amount,0) else 0.00 end)<>0
order by Account_Desc_out,Analysis_Desc_out,Sub_Analysis_Desc_out
View 1 Replies
View Related
Apr 18, 2008
Is there a difference if I use filter in the join instead in where clause:
1)
select s.*
from students s
join courses c
on s.ssn = c.ssn
and c.type = 'fresher'
2)
select s.*
from students s
join courses c
on s.ssn = c.ssn
where c.type = 'fresher'
Thanks...
View 5 Replies
View Related
Apr 21, 2008
Hi every one,
I want to filter application name in sql profiler, so I write SQL% (for every one who connects by sql qery analyzer) in "application name" filter box but it doesn't work correctly,and shows all applications. Why it works incorrect?
Thank You
Kini
View 1 Replies
View Related
Jun 16, 2008
Ok I am experimenting with the data in this database and trying to determine the best way to write this query. I need to find patients that visited in 2005 or 2006 but have not come back since. At first I was doing it looking at patients that have only came in one time ever and that being in 2005 and 2006 but I think I may be missing some patients. I want to narrow it to patients that came in during 2005 and 2006 but have not come back since but I think I am just getting an unduplicated list of patients that visited during those years. Am I on track to do this with the query I have written and if so any ideas?
With PersonMIA (person_id,person_nbr,first_name,last_name,date_of_birth) as
(
select distinct person_id,person_nbr,first_name,last_name,date_of_birth
from
(select count(*) as countenc,a.person_id,a.person_nbr,
a.first_name,a.last_name,
a.date_of_birth
from person a
join patient_encounter b on a.person_id = b.person_id
where year(b.create_timestamp) IN (2005,2006)
group by a.person_id,a.person_nbr,a.first_name,a.last_name,a.date_of_birth)tmp
/*where tmp.countenc <=1*/
)
select description,mstr_list_item_desc, count(*)
from
(
select distinct c.description,tmp.person_id,tmp.person_nbr,tmp.first_name,
tmp.last_name,tmp.date_of_birth,d.payer_name,year(b.create_timestamp)as YOS,f.mstr_list_item_desc
from PersonMIA tmp
join person a on a.person_id = tmp.person_id
join patient_encounter b on a.person_id = b.person_id
join provider_mstr c on b.rendering_provider_id = c.provider_id
cross apply(select top 1 payer_name,payer_id
from person_payer
where person_id = tmp.person_id
order by payer_id) d
join payer_mstr e on d.payer_id = e.payer_id
join mstr_lists f on e.financial_class = f.mstr_list_item_id
where c.description = 'Leon MD, Enrique' /*and
year(b.create_timestamp) IN (2005,2006)*/
group by c.description,tmp.person_id,tmp.person_nbr,tmp.first_name,
tmp.last_name,tmp.date_of_birth,d.payer_name,b.create_timestamp,
f.mstr_list_item_dessc)tmp2
group by description,mstr_list_item_desc
Thanks in Advance!
Sherri
View 10 Replies
View Related
Aug 10, 2013
How to write sql query that will filter between two dates (user input in text box1 and text box2) in the below sql statement .
SELECT 'Table1' AS [Table], SUM(a) - SUM(b) AS Result FROM table1 UNION ALL SELECT 'Table2', SUM(a) - SUM(b) FROM table2 UNION ALL SELECT 'Table3', SUM(a) - SUM(b) FROM table3
View 2 Replies
View Related