March 13, 2009 at 3:06 pm
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?
March 13, 2009 at 3:09 pm
foxjazz (3/13/2009)
cursors hehExcatly 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.
March 13, 2009 at 3:12 pm
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?
Jeffrey Williams
“We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”
― Charles R. Swindoll
How to post questions to get better answers faster
Managing Transaction Logs
March 13, 2009 at 3:13 pm
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
March 13, 2009 at 3:14 pm
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.
March 13, 2009 at 3:16 pm
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.
March 13, 2009 at 3:17 pm
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.
March 13, 2009 at 3:18 pm
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.
March 13, 2009 at 3:18 pm
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
March 13, 2009 at 3:18 pm
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?
March 13, 2009 at 3:20 pm
Let's give every employee a 10% raise:
update dbo.employee set
Salary = Salary * 1.1;
March 13, 2009 at 3:21 pm
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.
March 13, 2009 at 3:22 pm
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
March 13, 2009 at 3:22 pm
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!
March 13, 2009 at 3:23 pm
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 465 total)
You must be logged in to reply to this topic. Login to reply