looping in SQL Server2005
-
I have a table having columns like values, like this col1 col2 col3 1000 10 2 1000 20 3 1000 30 4 2000 10 5 2000 20 6 2000 30 7 3000 10 8 3000 20 9 3000 30 10 I want to fetch records like if i enter col2 as 20 and col1 as 1500 then with "SELECT col3 FROM table1 WHERE col2 = @col2" I will get 3 rows having respective records of value 20 for col2(col2 values are fixed) but col1 values are variable i.e. can fall into different ranges like 1400,1500,2300 etc. but col2 values are fixed I want to return only one row for eg. col2 as 20 and col1 as 1500 then 1000 20 3 this row should get returned How can i do this? I don't know how to use cursors...
-
I have a table having columns like values, like this col1 col2 col3 1000 10 2 1000 20 3 1000 30 4 2000 10 5 2000 20 6 2000 30 7 3000 10 8 3000 20 9 3000 30 10 I want to fetch records like if i enter col2 as 20 and col1 as 1500 then with "SELECT col3 FROM table1 WHERE col2 = @col2" I will get 3 rows having respective records of value 20 for col2(col2 values are fixed) but col1 values are variable i.e. can fall into different ranges like 1400,1500,2300 etc. but col2 values are fixed I want to return only one row for eg. col2 as 20 and col1 as 1500 then 1000 20 3 this row should get returned How can i do this? I don't know how to use cursors...
salon wrote:
I don't know how to use cursors...
Any problem for searching and learning how it works ?
All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions
-
salon wrote:
I don't know how to use cursors...
Any problem for searching and learning how it works ?
All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions
No issues to learn... I am just asking is there anyone have idea to do it in optimized way? as I am trying col1 have variable inputs like 1200,1300,2100 etc... and col2 have fixed inputs I am doing like this calculating min and max values for col1 and trying to put col2 in that range but till I m not able to achieve...
-
No issues to learn... I am just asking is there anyone have idea to do it in optimized way? as I am trying col1 have variable inputs like 1200,1300,2100 etc... and col2 have fixed inputs I am doing like this calculating min and max values for col1 and trying to put col2 in that range but till I m not able to achieve...
There's no problem in using a cursor within a while loop -> have a look at the MSDN, to review the example and you'll have your're problem solved.