Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
CLages
Posting Yak Master
116 Posts |
Posted - 2003-09-19 : 13:33:11
|
| Hi. I am new hereI have a table like thisCode , invoice, control, date, etc 48 123 17 48 333 01 .. .. 49 124 01 49 124 02 49 133 01 49 144 02.......as you can see there are a lot of records for each code(customer)there are a Forms with two buttons NEXT and PRIOR(back) the user type 49 and click NEXTI need to get 49 124 01if he click NEXT again, i get 49 124 02 if he click BACK, i will get 49 124 01 again and so onthere are no Listview is this forms, each field is shown one by oneI can not use CURSOR, because CURSOR limits a rangeex. if i declare CURSOR where CODE > 49 if User Clicks BACK button, i can get CODE 48.If I use SELECT * from table where code >= 49I will get always the same record, if i use>49 I wil get 50, 51, etc and not 49 124 001, etcis there a SELEC where i can take one by one ?tksCarlos LagesRio de Janeiro |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2003-09-19 : 13:49:18
|
| You can get the next or previous row if you have a column in your table that is numbered sequentially. To do this without modifying your table if you don't have this column, you could put your data into a temporary table that has the first column with an identity value. Then select on the temporary table.CREATE TABLE #Temp(Column1 INT IDENTITY (1, 1) NOT NULL,Column2 INT NOT NULLColumn3 INT NOT NULL)INSERT INTO #Temp (Column2, Column3)SELECT ColumnA, ColumnBFROM YourTable--now let's get the record that he wantsDECLARE @SomeValue INTSET @SomeValue = 4 -- this is the row that he wantsSELECT Column2, Column3FROM #TempWHERE Column1 = @SomeValue--to get the previous recordSELECT Column2, Column3FROM #TempWHERE Column1 = @SomeValue - 1--to get the next recordSELECT Column2, Column3FROM #TempWHERE Column1 = @SomeValue + 1Tara |
 |
|
|
CLages
Posting Yak Master
116 Posts |
Posted - 2003-09-19 : 14:19:28
|
tks. but i think this will not work .let us see why.1 - the table is to big, create a temporary table every timethe user wants to see some recors, will be to sloww2 - SELECT Column2, Column3 FROM #Temp WHERE Column1 = @SomeValue + 1the value of @somevalue is not changed, then every timethe user click NEXT, i wil get the same record. i will have to manager this.3 - there are 12 columns to be used in the same situation.the main ideia is something like thisthe use can choose to see the record bya - Zip code b - phonenumberc - IDd - LastNameetcbut phonenumber and ID there are no problems because one record for each Phone or ID , but ZIpcode , i have problemas because you and me can live in the same street , then i have to show you , me , and everybody who lives in the same adress.tkscarlos Lagesquote: Originally posted by tduggan You can get the next or previous row if you have a column in your table that is numbered sequentially. To do this without modifying your table if you don't have this column, you could put your data into a temporary table that has the first column with an identity value. Then select on the temporary table.CREATE TABLE #Temp(Column1 INT IDENTITY (1, 1) NOT NULL,Column2 INT NOT NULLColumn3 INT NOT NULL)INSERT INTO #Temp (Column2, Column3)SELECT ColumnA, ColumnBFROM YourTable--now let's get the record that he wantsDECLARE @SomeValue INTSET @SomeValue = 4 -- this is the row that he wantsSELECT Column2, Column3FROM #TempWHERE Column1 = @SomeValue--to get the previous recordSELECT Column2, Column3FROM #TempWHERE Column1 = @SomeValue - 1--to get the next recordSELECT Column2, Column3FROM #TempWHERE Column1 = @SomeValue + 1Tara
|
 |
|
|
|
|
|
|
|