Forum Replies Created

Viewing 15 posts - 586 through 600 (of 7,619 total)

  • Reply To: Subtract calculated columns

    Seems like you might be looking for a total?!:

    SELECT yt.account_number, SUM(ca1.Debit) AS Total_Debits, SUM(ca1.Credit) AS Total_Credits, 
    SUM(ca1.Debit) - SUM(ca1.Credit) AS Net_Amount
    FROM dbo.your_table yt
    CROSS...

    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: Proper CASE statement

    Use COALESCE instead:

    COALESCE(fa.S1SDAT, ar2.S1ADAT, ar.S1SDATE)

    ...

    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: Best table structure for a tall table that needs to be pivoted

    Definitely use char(2) for the values, as suggested (varchar requires two bytes of extra overhead (to store length) per column).

    If they're not already encoded, encode the names.  That is, "Code1"...

    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: A question about stored procedures and Transactions

    Yes, those procs will both run under the same transaction (assuming no COMMIT(s) in the procs).

    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: Query help

    ? Don't see anything attached ?

    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 a substring value from string

    carsten.saastamoinen wrote:

    No, a solution like this is hopefully only on few rows - as mentioned earlier, else change the way to solve the problem. And if my solution runs in...

    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: calculate 12 months of data from a given date from a user

    If you want only 12 months of data, then you'll need to restrict the ending date too.  Assuming you want to include the month that @Date is in, then:

    WHERE

    tblPropsFreeRent.dtMonth >=...

    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 a substring value from string

    select *, 
    case when last_bar = 0 or next_to_last_bar = 0 then ''
    else SUBSTRING(serialnumber,...

    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: SQL Syntax for BETWEEN any dates and specific time

    I'd be surprised if an index on a computed column ultimately helped the query plan at all.  Unless you have a fully covering index, which would likely duplicate most of...

    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: SQL Syntax for BETWEEN any dates and specific time

    Yes, it would.  I took:

    i want to select from 00:00:00 - 06:00:00

    to mean a contiguous range from 00 to 06, but I likely should have used 00 and 05, 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: record loading

    To keep the query on the remote server "sargable", you shouldn't use any function on its columns in the WHERE, so something more like this (I may not have 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: Grouping Same ID's with different Names

    Glad it helped!  Here's the 2nd version I mentioned: if you don't have more than 2 total dups, this might be easier to use.

    --(2)
    SELECT ID,
    ...

    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: SQL Syntax for BETWEEN any dates and specific time

    WHERE DATEPART(HOUR, datetime_column) BETWEEN 0 AND 6

    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: Grouping Same ID's with different Names

    If you want the details too, you can either:

    (1) join back to the main table to list all rows <or>

    (2) list the min, max and count

    --(1)
    SELECT t1.*
    FROM...

    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: Grouping Same ID's with different Names

    SELECT ID
    FROM #tst
    GROUP BY ID
    HAVING
    MIN(FNAME) <> MAX(FNAME) OR
    MIN(LNAME) <> MAX(LNAME) OR
    MIN(DOB) <> MAX(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".

Viewing 15 posts - 586 through 600 (of 7,619 total)