Query using "or" statement versus Query Using "Union All". Logically the same...
Trying to understand why these two queries which are logically the same do not use the same indexes.QUERY #1 SELECT TOP 400 * FROM AuditLog WITH ( NOLOCK ) WHERE CustomerID = 2379 AND PracticeID = 55...
View ArticleGroup By, needing to exclude a value in group by
Hi I'm selecting values from a table, but I need to select and include a column but it must not be included in the group by. If I include it in the group by 4 results are returned. I only need it to...
View ArticleCombining unrelated Selects
My data looks like this:date n1 n2 n3 n4 n5 2013-08-26 00:00:00 12 13 19 27 30 2013-08-25 00:00:00 6 17 21 30 31 2013-08-24 00:00:00 4...
View ArticleHourly Count for last 30 Days
Hello, Im using below query to get Count results for today. Declare @Hours Table (Hour int); Declare @i as int; Set @i = 0 While @i < 23 Begin Insert into @Hours Values(@i); Set @i = @i + 1;...
View ArticleUpdating large table take a long time.
I am trying to write a stored procedure to update a large table . The table is around 8M records and each time it will update around 15,000 records. Every time, it takes 60 seconds + which will end...
View Articleparent/child query help
Hello All,I have a parent table tbl_trade and a child table tbl_allocation. A trade can have many allocations. I'm trying to write a query which calculates the tbl_trade.isRec value. This should be...
View ArticleLoop Query Through Date Range
Hi all,I'm currently running a SQL script within Excel VBA.VBA loops through this script for every date that appears in a table. The dates are contiguous, but the start and end dates change based on...
View ArticleSQL Server 2008 R2 - Fetch Order - Retrieve related entity - Entity framework
Hi,I am facing a strange issue. Here is description - I have a Winform, database oriented application written in C# VS 4.0 [VS 2012]. I am using entity framework to communicate with SQL Server 2008 R2....
View ArticleSql server query for concatinating same column values if they are repeated
Hi I have a query as belowSELECT A.ClaimID, A.Member, B.Provider, B.ProcCD, B.ChargesAmt, C.PaidDate, D.CheckNo, E.PayeeName, E.PayeeIDFROM AJOIN B JOIN C JOIN D JOIN EIf I execute this query I will...
View ArticleDate and Time difference
Hi.I have 2 datetime columns for which I need to find the duration differences. I need to extract from this how many hours and minutes are between the two values. I also need to import this data into...
View ArticleDelete between dates on multiple columns
I would like to delete any records that are found BETWEEN say "2003 to 2008" . The fields below are of of a DATE/TIME type so I would like the query (shown below) to delete any record that is found...
View ArticleT-SQL that works, but needs a facelift!
Techies--This extracts what I need, but looks very late '80's. To make a long story short, I have table t1 with a real identifier I've dubbed as i . In table t2 I have comparable b,c values in both...
View ArticleSQL Interview Questions
Hi all How to answer below questions in interviews.1) I need to design the two tables customer and address tables.In customer table i have different customers,every customer have different address and...
View ArticleConsecutive Queries
Hi, I would like to perform the following query eleven times and put the results in a single result set. Two values will change with each itteration: s_id, '5.9.2013' (staff ID and a particular...
View ArticleUNION two FOR XML('tr') statements
I am trying to build an HTML structure like this: <tr><TD>John Doe (98210)</TD><TD>0.50</TD></tr><tr><TD>jane Smith...
View ArticleCounting business or working day minutes
HiI have a piece of SQL which works out hours and minutes between two dates:CONVERT(VARCHAR(10), DATEDIFF(MINUTE, D.RepairInstructed, A.EstimateReceived) / 60) + '.' + CASE WHEN LEN(DATEDIFF(MINUTE,...
View ArticleBEGIN AND END INSIDE TRY BLOCK
I HAVE FOLLOWING CODE STRUCTURE.BEGIN TRYIF EXISTS(CHECK IF VALUES EXISTS) BEGIN DO SOMETHING ENDEND TRYBEGIN CATCH LOG ERRORS INTO TABLEEND CATCHwith the...
View ArticleSearch All Databases on Server for a String in Particular Table Fields
Objective: Search for strings in several specified columns in various tables in all databases on a server.First, I need to find the strings I will be searching for. I think this is a two part...
View ArticleFast Script to Blank Out Part of Table Randomly
The table variable @Matrix contains a matrix (like a chessboard). There are 3 requirements:1. It has to be random blanking; FILLFACTOR 70 means 70% kept 30% blanked out2. Row wise the difference...
View ArticleSQL Function
SELECT DATEADD(minute,(DATEDIFF(minute,DayStart,[DateTime])/5)*5,DayStart) AS FiveMinutes, Val FROM (SELECT *, DATEADD(day,DATEDIFF(day,0,[DateTime]),0) as DayStart FROM table1) as AI would like to...
View Article