Viewing 15 posts - 361 through 375 (of 898 total)
winmansoft (2/27/2013)
You mean "select min([date]) from entries WHERE [date] BETWEEN '01-Jan-2012' and '20-Jan-2013'"? But we want to select minimum from top 100 rows
Chris has compared all the methods for you...
February 28, 2013 at 12:24 am
One way to achieve this
SELECT*
FROMB AS B
WHERE Status = 'Closed'
ANDNOT EXISTS( SELECT * FROM B AS B1 WHERE B.IDA = B1.IDA AND B1.IDA <> 'Closed' )
February 27, 2013 at 7:05 am
Gazareth (2/27/2013)
Your ascending ordering in the subquery means they're logically the same. If you were ordering by date descending then that would be a different matter.
Exactly.
winmansoft (2/27/2013)
February 27, 2013 at 2:54 am
Yes. It does and you can simplify it further as below
select min([date]) from entries WHERE [date] BETWEEN '01-Jan-2012' and '20-Jan-2013'
February 27, 2013 at 1:05 am
If there is a requirement where calling the stored procedure becomes unavoidable, a CURSOR or WHILE loop approach is fine and can't be avoided
But, if the requirement can be satisfied...
February 27, 2013 at 1:00 am
What is the need to use a sub-query?
I don't see any difference between the below queries or am I missing something.
SELECT min([date]) FROM table WHERE [date] IN (select top(100) [date]...
February 27, 2013 at 12:32 am
Warning: The table "Temp" has been created, but its maximum row size exceeds the allowed maximum of 8060 bytes. INSERT or UPDATE to this table will fail if the resulting...
February 27, 2013 at 12:10 am
There are 3 rows which are different as per the sample data provided
UPDATEOD
SETOD.FirstName = UD.FirstName,
OD.LastName = UD.LastName,
OD.Birthdate = UD.Birthdate,
OD.AreaCode = UD.AreaCode,
OD.PhoneNumber = UD.PhoneNumber
FROM#OriginalData AS OD
INNER JOIN #UpdatedData AS UD
ONOD.MemberID =...
February 26, 2013 at 11:44 pm
handkot (2/26/2013)
the answer is ambiguous and depends from collations
I agree somewhat
The answers will change if the database collation is case sensitive
But, overall a very good question.
February 26, 2013 at 11:26 pm
You can use Dynamic SQL to handle the scenario
But, be really careful about SQL Injection and take necessary steps to avoid it
CREATE PROCEDURE dbo.usp_ShowExpressionResults
(
@Expression NVARCHAR(MAX)
)
AS
BEGIN
SET @Expression = 'SELECT ' +...
February 26, 2013 at 5:46 am
Not sure, but I feel this is what you are after
SELECTL01, LO3, COUNT (*) Counts
FROM(
SELECTA.L01, A.L03, A.L39, B.A04, B.A10, B.A31
FROM[LEARNER_SN05]AS A
INNER JOIN(
SELECTL01, L03, A04, A10, A31
FROM[AIMS_SN05]
WHEREA04 <> 35
ANDA10 IN (10,...
February 26, 2013 at 3:20 am
This should give the result you are looking for..
DECLARE @t TABLE( ID INT, ColA CHAR(20), ColB CHAR(20), ColC CHAR(20) )
INSERT INTO @t(ID, ColA, ColB, ColC )
VALUES
( 1, 'India', 'VP', 'Mumbai'...
February 26, 2013 at 2:58 am
You can make some changes to Mark's query as below
DECLARE @t TABLE( ID INT, ColA CHAR(20), ColB CHAR(20), ColC CHAR(20) )
INSERT INTO @t(ID, ColA, ColB, ColC )
VALUES
( 1, 'India', 'VP',...
February 26, 2013 at 1:09 am
You can also use ROW_NUMBER()
SELECT*
FROM(
SELECTROW_NUMBER() OVER ( PARTITION BY CandidateID ORDER BY YourDateColumn DESC ) AS RN, *
FROMYourTable
) AS YT
WHEREYT.RN = 1
February 26, 2013 at 12:50 am
Another way using CROSS-APPLY
SELECTD.UnitNumber, D.IDXMRN, D.DischargeDate, App.ApptDt2, DATEDIFF( DAY, D.DischargeDate, App.ApptDt2 ) AS Days_Difference
FROMDischarges AS D
OUTER APPLY(
SELECTTOP 1 *
FROMAppointments AS A
WHERED.UnitNumber = A.UnitNumber AND D.IDXMRN = A.IDXMRN
ANDD.DischargeDate < A.ApptDt2
) AS...
February 26, 2013 at 12:38 am
Viewing 15 posts - 361 through 375 (of 898 total)