×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Building command based on response to ACCEPT statement

Building command based on response to ACCEPT statement

Building command based on response to ACCEPT statement

(OP)
Hello,

I'm relatively new to SQL and was wondering if its possible to do the following.

I have written a small .sql script that creates a select statement from a series of ACCEPT parameter prompts.

As I have it now I have prompts that get input for columns to select, table to select from & where clause

select &col from &table where &where
&col   columns to select
&table table to select from
&where where clause

I was wondering if it's possible to add an order by clause to the select command that would only be part of the command if the user entered a string for ordering the data and would leave out the order by statement if no string was entered at the order by prompt

If the following data was entered
  orderby:  col1 DESC
then the select statement would be as follows
  select &col from &table where &where orderby &orderby

If nothing was entered at ordrerby: prompt
then the select statement would not include order by &orderby.

Any help would be appreciated.

Thank you,
Michael

0

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources