T-Sql rant

  • foxjazzG

    SSCrazy

    Points: 2221

    cursors heh

    Excatly my point.... So why doesn't t-sql accomodate sets?

    Why would I need a cursor to do updates like ?

    foreach(select * from table)

    {

    insert into othertable (field) value(myfield) ? Why does this have to be a cursor. I use this type of stuff in .NET all the time.

    }

    Why again why can't t-sql get a datatable (inline) and that way cursors don't need to be used.

    This is my whole point you. Are you guys finally beginning to listen?

  • Lynn Pettis

    SSC Guru

    Points: 442118

    foxjazz (3/13/2009)


    cursors heh

    Excatly my point.... So why doesn't t-sql accomodate sets?

    Why would I need a cursor to do updates like ?

    foreach(select * from table)

    {

    insert into othertable (field) value(myfield) ? Why does this have to be a cursor. I use this type of stuff in .NET all the time.

    }

    Why again why can't t-sql get a datatable (inline) and that way cursors don't need to be used.

    This is my whole point you. Are you guys finally beginning to listen?

    Instead of C# psuedo code, why don't you give us a better example of what you don't seem to be able to do? The pseudo code you are writing may mean something to you, but to me its just gibberish.

  • Jeffrey Williams 3188

    SSC Guru

    Points: 88053

    foxjazz (3/13/2009)


    I don't think it's my problem that sql server is so inefficient with the use of cursors. Maybe they should have designed sql server better eh?

    Yes shortening of stuff would be a lot better, lest junk to type, that is one of my biggest complaints.

    I honestly don't get this attitude. Are you really typing that much T-SQL where saving a few characters is going to make a big difference?

    [font="Verdana"]Jeffrey Williams
    Problems are opportunities brilliantly disguised as insurmountable obstacles.

    How to post questions to get better answers faster[/url]
    Managing Transaction Logs[/url]
    [/font]

  • Lowell

    SSC Guru

    Points: 323361

    a cursor is like the add + function, where set based is like multiplication.

    Using addition as

    yeah you can do 2+2+2+2+2+2+2+2 = 16, because that's what you are used to,

    but the set based approach that TSQL uses 2*8=16; the set based approach takes an idea and extrapolates to solve the issue faster.

    it's just a mentality you have to get used to.

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • foxjazzG

    SSCrazy

    Points: 2221

    Ok here is what I would like to do:

    run a query or view that gets a datatable (in t-sql) not c#

    Then run through each record in the datatable that I have, and assign values to insert or update statements at my liesure.

    That is what I would like it to do. Should be easy right?

    And I don't want to have to use cursors to do it.

    Can this be done?

    I don't think it can, or haven't seen it in practice. Mostly I have to write code in c# to get sql to jump through the hoops I need it to with datatable or sets.

    This is why T-Sql sucks. This is why I rant.

    Unless I am wrong, then I would be pleasantly pleased, but I don't think I am wrong.

  • foxjazzG

    SSCrazy

    Points: 2221

    Another point, why should someone that knows c# or vb and does it daily, have to learn t-sql.

    Why can't t-sql accomadate that flavor of language just like the IDL compiler does for .net languages.

    WHY DO YOU HAVE TO GET USE TO IT?

    Thats' just a cop out.

  • Lynn Pettis

    SSC Guru

    Points: 442118

    foxjazz (3/13/2009)


    Ok here is what I would like to do:

    run a query or view that gets a datatable (in t-sql) not c#

    Then run through each record in the datatable that I have, and assign values to insert or update statements at my liesure.

    That is what I would like it to do. Should be easy right?

    And I don't want to have to use cursors to do it.

    Can this be done?

    I don't think it can, or haven't seen it in practice. Mostly I have to write code in c# to get sql to jump through the hoops I need it to with datatable or sets.

    This is why T-Sql sucks. This is why I rant.

    Unless I am wrong, then I would be pleasantly pleased, but I don't think I am wrong.

    Still waiting for a concrete example of what you are looking to do.

  • John Rowan

    SSC Guru

    Points: 56438

    You don't need a cursor for this. What you want to do can most likely be done with a few lines of code. Post an example of this insert/update you want to do for each row and we'll show you.

    John Rowan

    ======================================================
    ======================================================
    Forum Etiquette: How to post data/code on a forum to get the best help[/url] - by Jeff Moden

  • foxjazzG

    SSCrazy

    Points: 2221

    Gee lynn are you dense. Do I have to write it in t-sql for you to get it?

    I don't like cursors.

    wtf

  • Matt Miller (4)

    SSC Guru

    Points: 124173

    Unless I completely misread what you're asking for - there IS no need to use a cursor. You do have to acucmulate the "values you want to pass in "at your leisure" somewhere though - where is that happening?

    The whole advantage of using a set-engine like SQL server is to not have to write procedurally, but for set-based operations instead. so going to a cursor - you're not doing it right in just about every scenario in SQL Server (99.99% + of the time).

    The syntax you're looking for (set-based) would be :

    Insert Myothertable (MyOtherfieldlist)

    select MyFieldlist from MyTable

    As a small suggestion:I understand you did use the word RANT in the conversation title, but still - you attract more flies with honey than vinegar, so perhaps leaves the barbs out of the answers....

    ----------------------------------------------------------------------------------
    Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?

  • Lynn Pettis

    SSC Guru

    Points: 442118

    Let's give every employee a 10% raise:

    update dbo.employee set

    Salary = Salary * 1.1;

  • John Rowan

    SSC Guru

    Points: 56438

    foxjazz (3/13/2009)


    Another point, why should someone that knows c# or vb and does it daily, have to learn t-sql.

    Why can't t-sql accomadate that flavor of language just like the IDL compiler does for .net languages.

    I think the PC answer to this would be to keep the run-of-the-mill developer from thinking they were a database developer and writing poor performing DB code.

    John Rowan

    ======================================================
    ======================================================
    Forum Etiquette: How to post data/code on a forum to get the best help[/url] - by Jeff Moden

  • Gift Peddie

    SSC Guru

    Points: 73570

    also instead of using cursurs like they are now, wouldn't it be easier to say:

    foreach( select myfield from tbl where myotherfield > 3)

    {

    insert into myothertable (myotherfield) values (myfield)

    }

    If you could do that SQL Server will not be ANSI SQL compliant because there are no fields in ANSI SQL compliant RDBMS just columns and rows. When you get to know columns you will understand it is not a field.

    Kind regards,
    Gift Peddie

  • Lynn Pettis

    SSC Guru

    Points: 442118

    foxjazz (3/13/2009)


    Gee lynn are you dense. Do I have to write it in t-sql for you to get it?

    I don't like cursors.

    wtf

    Really? That is really necessary? No, I'm not dense. I'm just asking you to show me what you are asking for in a way that makes sense. Your psuedo code just doesn't do it for me.

    Now, keep it civil!

  • foxjazzG

    SSCrazy

    Points: 2221

    ok example sort of (my computer is sick so I can't give you something already done)

    select name from mynametable where changedate > @yesterday

    fetch from @sel into @name

    while (@@fetch_status = 0)

    begin

    insert into nameother (name,changeddate) values (@name,getdate())

    end

    Do this without a cursor!

Viewing 15 posts - 16 through 30 (of 466 total)

You must be logged in to reply to this topic. Login to reply