Results 1 to 15 of 15
  1. #1
    Join Date
    Mar 2006
    Posts
    82

    Unanswered: Why would this stop working

    Hey

    I have a statement that has been running great for the past hour but now it will not pull the info any longer and just gives me a null

    Code:
    DECLARE @Text VARCHAR(2000)
    SELECT @Text = COALESCE(@Text + '', '') + x.memotext
    FROM (SELECT TOP 100 PERCENT memotext FROM customermemoheader WHERE memonumber = 'TERMS' and customernumber = '0009' ORDER BY seqnumber) AS x
    
    SELECT @Text AS MemoText
    I have verified in the tables that the info is there by running the select statement from within the (). It has worked for 8000 records and now it no longer works. Any help would be much appreciated.

    THanks

  2. #2
    Join Date
    Nov 2004
    Location
    on the wrong server
    Posts
    8,835
    Provided Answers: 6
    do you have any nulls in memotext

    do this...

    SELECT top 100 * FROM customermemoheader WHERE memonumber = 'TERMS' and customernumber = '0009' and memotext is null
    “If one brings so much courage to this world the world has to kill them or break them, so of course it kills them. The world breaks every one and afterward many are strong at the broken places. But those that will not break it kills. It kills the very good and the very gentle and the very brave impartially. If you are none of these you can be sure it will kill you too but there will be no special hurry.” Earnest Hemingway, A Farewell To Arms.

  3. #3
    Join Date
    Mar 2006
    Posts
    82
    It is still comingup null

  4. #4
    Join Date
    Nov 2004
    Location
    on the wrong server
    Posts
    8,835
    Provided Answers: 6
    let me be a little more clear. Do you get records back from the sql I posted. If so you have records with null values in memotext. If you concatenate null with anything you get null returned. The query I wrote for you has the condition "and memotext is null" which will return records that break your code.
    “If one brings so much courage to this world the world has to kill them or break them, so of course it kills them. The world breaks every one and afterward many are strong at the broken places. But those that will not break it kills. It kills the very good and the very gentle and the very brave impartially. If you are none of these you can be sure it will kill you too but there will be no special hurry.” Earnest Hemingway, A Farewell To Arms.

  5. #5
    Join Date
    Mar 2006
    Posts
    82
    Code:
    NOT memotext is null
    worked.

    thanks

  6. #6
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Is the TOP 100 PERCENT really necessary?

    And personally I use "IS NOT NULL"
    George
    Home | Blog

  7. #7
    Join Date
    Mar 2006
    Posts
    82
    It gives me this error when i dont use TOP 100 PERCENT


    The ORDER BY clause is invalid in views, inline functions, derived tables, and subqueries, unless TOP is also specified.

  8. #8
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    I never noticed you were ordering too..

    Why are you ordering your subquery?
    George
    Home | Blog

  9. #9
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Anyone want to ask why there is an ORDER BY Clause in the first place?

    And to a Singleton variable assignment?

    bleeech
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  10. #10
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Quote Originally Posted by georgev
    I never noticed you were ordering too..

    Why are you ordering your subquery?

    Thank you

    AND I betcha this is all done in a loop
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  11. #11
    Join Date
    May 2004
    Location
    Seattle
    Posts
    1,313
    you might want to learn about ordering guarantees. your ORDER BY clause may be ignored by the optimizer.

    see: http://blogs.msdn.com/sqltips/archiv...20/441053.aspx
    Last edited by jezemine; 09-07-07 at 10:50.

  12. #12
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    It is perfectly legitimate to write out csvs like this with an order by. Depends on the application.

    As pointed out there is an error though:
    Code:
     
    DECLARE @Text VARCHAR(2000) SELECT @Text = COALESCE(@Text + '', '') + memotext FROM customermemoheader WHERE memonumber = 'TERMS' and customernumber = '0009' ORDER BY seqnumber SELECT @Text AS MemoText
    Testimonial:
    pootle flump
    ur codings are working excelent.

  13. #13
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Quote Originally Posted by pootle flump
    It is perfectly legitimate to write out csvs like this with an order by.

    Yeah, that's real ANSI

    Try that on DB2 or Oracle, or any singleton select that's suppose to assign to a host variable


    BOOOOOOOOOOOOOOOOOOOOM
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  14. #14
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Quote Originally Posted by Brett Kaiser
    Yeah, that's real ANSI
    It is SQL Server not ANSI Server. Building up a string like this is propietry to SQL Server (AFAIK) so why not use an order by clause? Order by (you know - logical ordering) is ANSI. It is the building up a string in this fashion that is (again AFAIK) not.
    Testimonial:
    pootle flump
    ur codings are working excelent.

  15. #15
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Quote Originally Posted by pootle flump
    It is SQL Server not ANSI Server. Building up a string like this is propietry to SQL Server (AFAIK) so why not use an order by clause? Order by (you know - logical ordering) is ANSI. It is the building up a string in this fashion that is (again AFAIK) not.

    Live the drea....ummmmm fantasy
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •