Forum Replies Created

Viewing 15 posts - 106 through 120 (of 921 total)

  • RE: sql query requirement

    SELECT CONVERT(char(12),dt,113)

    FROM

    (SELECT MIN(Dt) dt

     FROM Dates

     UNION ALL

     SELECT TOP 4 dt

     FROM

     (SELECT MAX(Dt) dt

      FROM Dates

      WHERE Dt <

      (SELECT MAX(Dt)

       FROM Dates)

      GROUP BY CONVERT(char(6),Dt,112)) m

     ORDER BY dt DESC

     UNION ALL

     SELECT MAX(Dt)

     FROM Dates)...

  • RE: TimeSheet - Date Time

    SELECT i.FEmpID, i.FTime FTimeIn, o.FTime FTimeOut, CONVERT(char(5),o.FTime - i.FTime,14) Hours

    FROM Punches i LEFT JOIN Punches o ON i.FEmpID = o.FEmpID AND o.FType = 'OUT'  AND o.Ftime =

    (SELECT MIN(FTime)

     FROM Punches

     WHERE...

  • RE: Monthly contest

    I'll come right out and say that I think the quality of answers declined markedly since the contests started.  I essentially stopped posting once the quantity over quality motivation became...

  • RE: Puzzling SQL

    You're welcome.  Notice how much easier it is to find a solution once you provide some hard information. 

    Actually, you may want this...

  • RE: Puzzling SQL

    SELECT e.Event_Number, e.DtTm_Rcd_Added, ep.First_Name + ' ' + ep.Last_Name PatientName,

     ev.First_Name + ' ' + ev.Last_Name Vistor, v.Pi_Type_Code, g.System_Table_Name

    FROM Event e

     JOIN Person_Involved p ON e.Event_Id = p.Event_Id AND p.Pi_Type_Code = 238

     JOIN...

  • RE: Puzzling SQL

    SELECT e.Event_Number, e.DtTm_Rcd_Added, ep.First_Name + ' ' + ep.Last_Name PatientName,

     ev.First_Name + ' ' + ev.Last_Name Vistor, v.Pi_Type_Code, g.System_Table_Name

    FROM Event e

     JOIN Person_Involved p ON e.Event_Id = p.Event_Id AND p.Pi_Type_Code = 238

     JOIN...

  • RE: i have a complicated problem

    Are you looking for something like this?

    SELECT d.DeptName, e.EmpName, e.Salary

    FROM Employees e JOIN Departments d ON e.DeptCode = d.DeptCode

    JOIN

    (SELECT DeptCode, MAX(Salary) Salary

     FROM Employees

     GROUP BY DeptCode) x ON e.DeptCode = x.DeptCode...

  • RE: Spilt string into seperate fields

    It doesn't work (without tweaking; notice I chopped the first piece off) unless you have four or fewer pieces to extract.  PARSENAME() is also limited to 128 characters per piece...

  • RE: Alternative to cursor

    Without knowing what columns belong to which tables, I cannot confidently write your query, but perhaps this will help you understand how to do this:

    USE Northwind

    GO

    SELECT r.CustomerID, r.OrderID, SUM(e.UnitPrice *...

  • RE: Field with mixed case characters

    No need for a function.  If the column is longer than 30 characters, then adjust the length of the varbinary type being casted.

    SELECT CASE WHEN CAST(Col AS varbinary)=CAST(UPPER(Col) AS varbinary)...

  • RE: Spilt string into seperate fields

    Assuming there may be periods but no tildes or carets in the data:

    SELECT Account, Address, LEFT(Address,CHARINDEX(';',Address)-1) Address1,

    REPLACE(REPLACE(PARSENAME(REPLACE(REPLACE(STUFF(Address,1,CHARINDEX(';',address),''),'.','~'),';','^.^'),4),'^',''),'~','.') Address2,

    REPLACE(REPLACE(PARSENAME(REPLACE(REPLACE(STUFF(Address,1,CHARINDEX(';',Address),''),'.','~'),';','^.^'),3),'^',''),'~','.') Address3,

    REPLACE(REPLACE(PARSENAME(REPLACE(REPLACE(STUFF(Address,1,CHARINDEX(';',Address),''),'.','~'),';','^.^'),2),'^',''),'~','.') Address4,

    REPLACE(REPLACE(PARSENAME(REPLACE(REPLACE(STUFF(Address,1,CHARINDEX(';',Address),''),'.','~'),';','^.^'),1),'^',''),'~','.') Address5

    FROM AddrSrc

  • RE: Cross-Tab Question

    Not without dynamic SQL.

  • RE: Getting the most recent row for a group of products

    USE Northwind

    GO

    CREATE TABLE #Basket(

    CustomerID nchar(5),

    ProductID int,

    Qty smallint)

    INSERT #Basket

    SELECT 'SAVEA',1,4

    UNION ALL SELECT 'SAVEA',2,2

    UNION ALL SELECT 'SAVEA',13,1

    SELECT ProductId,

    (SELECT TOP 1 UnitPrice

     FROM [Order Details] d JOIN Orders o ON d.OrderID = o.OrderID

     WHERE...

  • RE: Multiple Parameters in the IN Clause

    How about using an inner join?  That should be simpler and more efficient.

    SELECT t1.*

    FROM Table1 t1 JOIN Table2 t2 ON t1.Id1 = t2.Id1 AND t1.Id2 = t2.Id2

  • RE: First Day of Next Month

    SELECT CAST(LEFT(GETDATE()-DAY(GETDATE()),11) AS datetime) LastDayLastMo,

    CAST(LEFT(GETDATE()-DAY(GETDATE())+1,11) AS datetime) FirstDayThisMo,

    CAST(LEFT(DATEADD(m,1,GETDATE()-DAY(GETDATE())+1),11) AS datetime) FirstDayNextMo

Viewing 15 posts - 106 through 120 (of 921 total)