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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Simple Select Statement OrderBy

Author  Topic 

slackerksg5
Starting Member

3 Posts

Posted - 2008-02-04 : 14:04:17
Well my problem lies in that I am generating reports with the data I retrieve from my sql database. However my problem resides in the fact that I am generating one report at a time and if I want to grab each entry in the order in which they were produced its no problem.

IE - Using PowerBuilder 10.0 as an IDE for my application to generate reports.

select i_id into :insp_id from inspection where i_id = :index order by i_id asc using sqlca;

But now if I want to grab them in alphabetical order from another table I have problems.

this is the code I am trying to use maybe I am just thinking it through wrong.
select s_id into :insp_id from section where s_id = :index order by s_name asc using sqlca;

any help is appreciated. Is there a way to grab each row in alphabetical order?

slackerksg5
Starting Member

3 Posts

Posted - 2008-02-04 : 14:23:29
Maybe this will help.

create table section(
s_id integer primary key,
s_guid integer,
job_id integer not null,
node1_id integer,
node2_id integer,
s_node1_icon integer,
s_node2_icon integer,
s_parent_ID integer,
s_name varchar(64) not null,
s_type integer,
s_length numeric,
s_uom varchar(8),
s_readonly bit,
s_material integer,
s_shape integer,
s_diameter numeric,
s_width numeric,
s_lining integer,
s_seg_length numeric,
s_year_built integer,
s_year_renewed integer,
s_street varchar(128),
s_city varchar(128),
s_division varchar(32),
s_district varchar(32),
s_drain_area varchar(32),
s_map_number varchar(32),
s_owner varchar(32),
s_category integer,
s_area integer,
s_location integer,
s_location_details varchar(255),
s_notes varchar(255),
s_no_taps integer,
s_house_no varchar(6),
s_post_dir integer,
s_pre_dir integer,
s_svc_ln_depth numeric,
s_subarea integer,
s_suffix varchar(4),
s_surface_type integer,
s_tap_dist numeric,
s_tfnode_id integer,
s_joint_type integer,
s_district_id integer,
s_assigned bit,
s_televised bit,
s_new_asset bit,
constraint fk_node2_id foreign key(node2_id)
references node(n_id),
constraint fk_node1_id foreign key(node1_id)
references node(n_id),
constraint fk_tfnode_id foreign key(s_tfnode_id)
references node(n_id),
constraint fk_s_job_id foreign key(job_id)
references job(j_id));

Oh and sorry I didn't explain what :index was. :index is a counter that increases when you press the "Next" button to view the next report.

so if there are 30 sections than index would = 1-30
Go to Top of Page

LoztInSpace
Aged Yak Warrior

940 Posts

Posted - 2008-02-04 : 22:54:36
Not sure what you mean. You have only given one table so how does the other table come into it. Are you asking about doing joins?
Go to Top of Page

slackerksg5
Starting Member

3 Posts

Posted - 2008-02-05 : 11:17:45
No. I apologize the other table was just an example of something that works. This table is the one that I need to grab information from and specifically the S_Name (Section Name), but I need to grab than in alphabetical order. Sounds simple enough, but I really need to grab one row at a time... is my problem. Otherwise I could simply go

Select S_name from section order by S_name asc;

but as I said I need to grab a single row at a time and by using the s_id as a where clause defeats the whole purpose of grabbing the s_name.
Go to Top of Page
   

- Advertisement -