Forum Replies Created

Viewing 15 posts - 46 through 60 (of 86 total)

  • RE: string building

    You have ([Severity] = @Severity OR [Severity] <> '')

    It should be ([Severity] = @Severity OR @Severity = '')

    If the value that is passed in is an empty string, it will...

  • RE: Database design

    Hmm... This looks an awful lot like homework. Why don't you post what you think the design should look like and maybe someone will critique it?

    Greg

  • RE: string building

    I always avoid using dynamic SQL. Your WHERE clause could look like this instead:

    WHERE (Username = @Username OR @Username = '')

    Basically it will use the username if it's supplied...

  • RE: query not filtering

    I would do something like this:

    Here I'm setting variables and adding comma before and after the input strings

    DECLARE @State VARCHAR(100), @Region VARCHAR(100)

    SELECT @State = '1, 2, 3, 4, 5, 6,...

  • RE: query not filtering

    You shouldn't need to use dynamic SQL at all. If @Region and @State are some sort of comma delimited string, I would parse them into table variables and join...

  • RE: Returning part of a field

    Try this:

    SELECT SUBSTRING(ColumnName, CHARINDEX('\', ColumnName) + 1, 100)

    FROM TableName

    Greg

  • RE: Count To Include Nulls

    It's probably the * in Count(*). Instead, select a column from the table that has the records that you are counting.

    Greg

  • RE: Count To Include Nulls

    I would use a LEFT OUTER JOIN so that all results are returned regardless if they match or not. And then use ISNULL(COUNT(*), 0) AS 'Count' so that zeros...

  • RE: Simple SELECT for Inoices with certain Items

    Oops! I posted to both! I thought that they were the same post and assumed that I accidentally closed the window the first time without posting.

    Greg

  • RE: Simple SELECT for Inoices with certain Items

    I would use NOT EXISTS instead of NOT IN for better performance like this:

    SELECT DISTINCT a.InvoiceID

    FROM TestTable a

    WHERE NOT EXISTS

    (SELECT * FROM TestTable b

    WHERE...

  • RE: Simple SELECT for Invoices with certain Items

    I would use NOT EXISTS instead of NOT IN like this:

    SELECT DISTINCT a.InvoiceID

    FROM TestTable a

    WHERE NOT EXISTS

    (SELECT * FROM TestTable b

    WHERE a.InvoiceID = b.InvoiceID...

  • RE: Date Format (mm/dd/yyyy hh:mm), no seconds or milliseconds

    Try this:

    SELECT CONVERT(VARCHAR, GetDate(), 101) + ' ' +

    CONVERT(VARCHAR, DATEPART(hh, GetDate())) + ':' +

    RIGHT('0' + CONVERT(VARCHAR, DATEPART(mi, GetDate())), 2) AS Date

    Greg

  • RE: Sorting by character field

    SQL won't sort it that way by default because '{{{' comes before 'www' alphabetically. You could sort by ASCII code like you suggest, although I can't guarantee that it...

  • RE: Sorting by character field

    When ordering a string, it uses alphabetical order.

    NULLs are the lowest value,

    then special characters,

    then numbers,

    then letters.

    Greg

Viewing 15 posts - 46 through 60 (of 86 total)