Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search results for query: *

  1. pwilson

    Join With Min(date)

    The MinID makes sense. I dropped the Date=Date and it works the same. thanks for the help.
  2. pwilson

    Join With Min(date)

    Its an ugly hack but this works. SELECT * FROM TestEmp E LEFT OUTER JOIN (SELECT DL.DateItem,DL.ID,DL.EmpId,DL.Note FROM TestDateLog DL INNER JOIN (SELECT MIN(DATEADD(ms,ID,DateItem)) AS DateItem, EmpID FROM TestDateLog GROUP...
  3. pwilson

    Join With Min(date)

    Well say note is a text field. ALTER TABLE TestDateLog ALTER COLUMN Note text NULL The text, ntext, and image data types are invalid in this subquery or aggregate expression. And what if there are more columns than just Note to be pulled from TestDateLog. Thanks for looking at it.
  4. pwilson

    Join With Min(date)

    Employees Id Name 1 Joe 2 Carol 3 Susan DateLog ID date Employee Note 1 10-1 1 Fun 2 10-1 1 Great 3 10-10 3 monkeys rule 3 12-12 3 i like elephants So I want All employees with their earliest date applied, but also the...
  5. pwilson

    ISO Weeks

    Ok this looks like it works ALTER PROCEDURE ISODates @finddate datetime AS SET DATEFIRST 1 DECLARE @seed datetime DECLARE @firstdayyear datetime SET @seed = (SELECT DATEADD(yy,DATEDIFF(yy,'1/1/2000',@finddate),'1/1/2000')) SET @firstdayyear = (SELECT...
  6. pwilson

    ISO Weeks

    This is close. It messes up on the week for 12/29/2009, 1 instead of 53. ALTER PROCEDURE ISODates @finddate datetime AS SET DATEFIRST 1 DECLARE @seed datetime SET @seed = (SELECT DATEADD(yy,DATEDIFF(yy,'1/1/2000',@finddate),'1/1/2000')) SELECt DATEPART(yy...
  7. pwilson

    Better Database design?

    FYI: we dont have daylight savings where I live ... along the daylight saving thing what happens in the time that that occurs. Say that 2Am (or whenever daylight saving starts) you make some records 4-1-2004 2.00.01 am 4-1-2004 2.01.01 am 4-1-2004 2.02.01 am 4-1-2004 2.03.01 am then at...
  8. pwilson

    SQL weirdness

    Why does the second one not work. Is it because the IN function goofs on the null or what?
  9. pwilson

    SQL Server Puzzle #5: Points Within Polygon

    von, you write some quick stuff CREATE PROCEDURE County_pwilson AS Declare @StartTime DateTime Declare @MidTime DateTime Declare @EndTime DateTime Declare @EndTime2 DateTime Set @StartTime = GetDate() DECLARE @maxpoint int SELECT @maxpoint = MAX(PointNumber) FROM MapPoints Set @EndTime =...
  10. pwilson

    SQL Server Puzzle #5: Points Within Polygon

    I figured that one out after I posted. I did the algorithm wrong. Ok now im down to 3754 in 13.36
  11. pwilson

    SQL Server Puzzle #5: Points Within Polygon

    I am getting 3854. Are there 1464 MapPoints and 4166 Locations?
  12. pwilson

    SQL Server Problem #2: data dump

    In researching how to do it I found one that does most of what was asked. Didnt want to plagiarize or redo it.
  13. pwilson

    SQL Server Puzzle:Prime Numbers

    My eratosthenes took about 10 secs longer than that replacing the Join part with DECLARE @i int SET @i = 2 WHILE @i < SQRT(@NumRows) BEGIN DELETE FROM #t WHERE RowNum%@i=0 AND RowNum > @i SET @i = (SELECT MIN(RowNum) FROM #t where RowNum>@i) END
  14. pwilson

    SQL Server Puzzle:Prime Numbers

    Here is mine Found the Table generation from this site. Modded it to be from n^2 to n^n with a limit so i wouldnt be joining 100000 twice. #t is numbers 1 to @NumRows #j is numbers 1 to SQRT(@NumRows) This is because of the following in the list 1,2,3,4,5,6 if you delete the multiples of 2...
  15. pwilson

    Learn SQL Server the hard way

    On a Sybase app I was creating a package that pulled some random numbers. so i did something like SELECT Rand(Column * (datepart(ms,getdate())) Well on sybase the seed you pass in there is a global seed. There was a row with a zero causing the rand(0) = 0. Since Sybase sets the seed to a...
  16. pwilson

    SQL Server Puzzle:Prime Numbers

    Very fun problem. Making me think I have ~34 seconds with ~6 seconds of table generation.
  17. pwilson

    SQL puzzles

    Changing the +6 to +5 then maving the +1 to the outside seems to do it declare @WhichDay tinyint -- US English datefirst assumed (1 - Sunday) declare @StartDate datetime set @StartDate = '20060111' set @WhichDay = 4-- next wed 1-18 //1-18 SET DATEFIRST 7 SELECT...
  18. pwilson

    SQL puzzles

    declare @WhichDay tinyint -- US English datefirst assumed (1 - Sunday) declare @StartDate datetime set @StartDate = '20060111' set @WhichDay = 1-- next Sunday, result should be Jan 15th //returns 1-16 SET DATEFIRST 7 SELECT (6 + (@WhichDay + DATEPART(dw, @StartDate))) % 7 + @StartDate +...
  19. pwilson

    SQL puzzles

    ok then DECLARE @nextday int SET @nextday = 7 SET DATEFIRST 1 SELECT DATEADD(dd,DATEDIFF(dd,'1/1/1900',getdate()) + (@@DateFirst + @nextday + DATEPART(dw,Getdate())) % 7 +1,'1/1/1900') SET DATEFIRST 3 SELECT DATEADD(dd,DATEDIFF(dd,'1/1/1900',getdate()) + (@@DateFirst + @nextday +...
  20. pwilson

    SQL puzzles

    DECLARE @nextday int SET @nextday = 7 SELECT DATEADD(dd,DATEDIFF(dd,'1/1/1900',getdate()) + (@nextday + DATEPART(dw,Getdate())) % 7 +1,'1/1/1900')

Part and Inventory Search

Back
Top