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 |
sharaiqa
Starting Member
7 Posts |
Posted - 2007-02-06 : 09:47:17
|
I have 2 million rows of data. I am trying to use this select statement but I can't seem to get it to work. I need three examples of each state by state_code. Can someone look at this and tell me what I am doing wrong...EXEC SQL BEGIN DECLARE SECTION;v_counter INTEGER DEFAULT 0;v_given VARCHAR(12);v_surname CHAR(22);v_surname VARCHAR(60);v_city VARCHAR(13);v_state VARCHAR(2);v_zip VARCHAR(5);v_census_tract VARCHAR(12);v_matchcode VARCHAR(22);v_state VARCHAR(2);v_state_code VARCHAR(2);v_c1 CURSOR FOREXEC SQL END DECLARE SECTION; SELECT given, surname, address, city, state, zip, census_tract, matchcode, state_code, stateFROM ethnic_vendor_data;DECLARE CONTINUE HANDLER FOR NOT FOUNDSET counter = -1;OPEN c1;fetch_loop:LOOPFETCH c1 INTO v_given; v_surname; v_lastname; v_surname; v_city; v_state; v_zip; v_census_tract; v_matchcode; v_state; v_state_code;IF v_state = ' ' THENLEAVE fetch_loop;END IF;SET v_counter = v_counter + 1;END LOOP fetch_loop;SET counter = v_counter;CLOSE c1;BEGIN... END; |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
|
sharaiqa
Starting Member
7 Posts |
Posted - 2007-02-06 : 09:51:43
|
i have the correct forum now |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-02-06 : 10:25:47
|
[code]SELECT s.State, s.State_CodeFROM ( SELECT DISTINCT State_Code, State FROM Ethnic_Vendor_Data ) AS sCROSS JOIN ( SELECT 1 AS u UNION ALL SELECT 2 UNION ALL SELECT 3 ) AS xORDER BY s.State, s.State_Code[/code]Peter LarssonHelsingborg, Sweden |
|
|
Kristen
Test
22859 Posts |
Posted - 2007-02-06 : 10:53:59
|
"i have the correct forum now"So you are not using Oracle any more? !! |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-02-06 : 20:53:42
|
I guess sharaiqa did not gets his question on Oracle answered, has switched to SQL Server. KH |
|
|
|
|
|
|
|