Forum Replies Created

Viewing 15 posts - 346 through 360 (of 7,613 total)

  • Reply To: query to find the date/s that each user missing to signed in his attendance

    And to make the code not reliant on a particular DATEFIRST setting, don't use DATEPART, instead do this:

    ...
    AND DATEDIFF(DAY, 0, a.date) % 7 <> 4 -- Ensure...

    SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".

  • Reply To: Can LEAD and LAG skip rows or can we add a where clause?

    tacy.highland wrote:

    I need just the passenger events (0 or o,1).  But I think I may have gotten the answer from a colleague:

    SELECT costCenterCode, scheduleDate, tripid, routeId, routename, activityId, eventOrder, CASE...

    SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".

  • Reply To: Splitting delimited values across multiple columns on same row.

    It's just another expression per value, not statement.  You could pre-code 10 or even 20 values without a lot of trouble:

    SELECT ResourceType, CustomerID, DOB,
    ...

    SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".

  • Reply To: Can LEAD and LAG skip rows or can we add a where clause?

    I'm not sure I fully understand the requirements.

    Do you need the first and last [activityId] = 0 / IN (0, 1) in the partition regardless, or does some other row...

    SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".

  • Reply To: How to get 2nd max value if 1st max is null

     

    WITH cteRowNum(GroupName,AgentName,AgentEmail,

    TicketsCompleted, RowNums) AS (

    SELECT GroupName,AgentName,AgentEmail,TicketsCompleted,

    DENSE_RANK() OVER(PARTITION BY GroupName ORDER BY TicketsCompleted DESC) AS RowNums

    FROM Table

    WHERE AgentName IS NOT NULL

    )

    SELECT cteRowNum.GroupName,cterowNum.AgentName,cteRowNum.AgentEmail, cteRowNum.TicketsCompleted

    FROM cteRowNum

    WHERE cteRowNum.RowNums = 1;

    SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".

  • Reply To: Select a distinct list of values from tables, return the dataset

    I assume you could have a Function2 and then data for it.  If so, there needs to be something to order the rows: an identity column, a datetime, etc..  Do...

    SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".

  • Reply To: Reorganising field in a table

    Perhaps you could create a view with the columns in your (client's) preferred order?  It it was a full view, it should be updatable and therefore the view name could...

    SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".

  • Reply To: I can query one by one. Need help how to become Single Query

    SELECT
    SUM(CASE WHEN HowManyDays <= 30 THEN thisAmt ELSE 0 END) AS aging_0_30,
    SUM(CASE WHEN HowManyDays >= 31 AND HowManyDays <=...

    SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".

  • Reply To: Baking up and restores VLDBs

    (1) Use differentials rather than full backups for most backups.  For example, daily diffs and only, say, weekly full backups.

    (2) If you're not already using backup compression, and particularly if...

    SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".

  • Reply To: Convert common Separated number to # table

    The value needs to be a string:

    STRING_SPLIT('1008,1009,1011,1014',',')

    SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".

  • Reply To: ASCII value of certain column is null

     

    A NULL value should not cause an error, ASCII(NULL) should just return NULL.

    SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".

  • Reply To: get week number of month

    How do you define "week number"?  Are the first 7 days of the month "week 1", or is it based on specific day of the week?  For example, all weeks...

    SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".

  • Reply To: High tempdb usage alternatives

    Increase the size of  your tempdb files.

    SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".

  • Reply To: Hello i am new to Sql and idk why i get this error and also not getting results.

    Inside that same db, run this command:

    EXEC sys.sp_help tblstudent

    or this:

    SELECT * FROM sys.columns WHERE name = 'tblstudent'

    Either of those should give you info about the table to compare to the...

    SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".

  • Reply To: Hello i am new to Sql and idk why i get this error and also not getting results.

    "tblstudent" already exists -- with a different number of columns -- so the create table statement is failing, but the insert still tries to execute.

    SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".

Viewing 15 posts - 346 through 360 (of 7,613 total)