Sponsored Content
Full Discussion: Help writing SQL query
Top Forums Programming Help writing SQL query Post 302924250 by durden_tyler on Friday 7th of November 2014 08:04:58 AM
Old 11-07-2014
Quote:
Originally Posted by bbbngowc
...
...
...
Perhaps something like this would work.

Code:
SELECT EmployeeID, FirstName, LastName, Email FROM Employees
WHERE Ticket = 'ticketnumber'

The only question I have from this is, how to get the query to cycle through a list of ticket numbers?
It's not clear from your post what your table looks like.
  1. Does the "Employees" table have a column called "Ticket"?
  2. If ticket information is stored in a separate table, then how are these two tables (Employees and the ticket table) related?
    1. Is there a column in the ticket table that points to or references the "Employees" table? In other words, does the ticket table have a foreign key to the "Employees" table?

As Jim mentioned, the "describe" command will provide you information about the table structure. It should be run in SQL*Plus (GUI or command-line). Or you could use any of the ad-hoc query tools like TOAD, SQL Developer, SQL Navigator, PL/SQL Developer etc. that your company provides and view the table structures by clicking.

Assuming the query you posted runs successfully in your schema, you could use the following query to fetch information about multiple tickets:

Code:
SELECT Ticket, EmployeeID, FirstName, LastName, Email FROM Employees
WHERE Ticket IN ( 'ticketnumber_1', 'ticketnumber_2', 'ticketnumber_3', 'ticketnumber_4' );


Last edited by rbatte1; 11-12-2014 at 08:56 AM.. Reason: Added LIST=1 tags & LIST=a tags
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

conditional writing of sql code

Hello again... I have a request from another department to list for them all the columns and tables we use in this certain database. I have spooled the oracle stored procedured into 1 file. I need a way to write out parts of that file. The criteria is to to start the block to be written when... (0 Replies)
Discussion started by: kburrows
0 Replies

2. Shell Programming and Scripting

& in SQL query

I have a script that looks for all jobs that contain a particular calendar. Some of the calendars have '&' in them and sql freaks out when it encounters that.. is there a way around this? I have tried: select job_name from job where run_calendar='1&15dom' select job_name from job... (3 Replies)
Discussion started by: Lindarella
3 Replies

3. Programming

Writing to a File using pl/sql

Hi I am new to using pl/sql on a unix platform and am having trouble writing to a file from within a block. Below is an example of the code that I have. I know that I need to use UTL_FILE to accomplish this; however, I keep getting errors. Can someone please help me? I am trying to create a... (1 Reply)
Discussion started by: stky13
1 Replies

4. Shell Programming and Scripting

writing the output of SQL into one file

Hi All, Please help me writing the below script. I have two sql queries. 1. Select count(1),Client_id from TABLE_A group by Client_id; 2. Select count(1),Client_id from TABLE_B group by Client_id; I need the output of above two sql queries in a single file. The output 2nd query should be... (4 Replies)
Discussion started by: 46019
4 Replies

5. Shell Programming and Scripting

How to use sql data file in unix csv file as input to an sql query from shell

Hi , I used the below script to get the sql data into csv file using unix scripting. I m getting the output into an output file but the output file is not displayed in a separe columns . #!/bin/ksh export FILE_PATH=/maav/home/xyz/abc/ rm $FILE_PATH/sample.csv sqlplus -s... (2 Replies)
Discussion started by: Nareshp
2 Replies

6. Shell Programming and Scripting

Writing sql results to file using ksh -nevermind

I'm having problems with writing my sql results to a file: sqlplus -S username/password@DB <<!! set echo off set verify off set showmode off set feedback off set timing off set linesize 250 set wrap off set pagesize 0 set newpage none set tab off set trimspool on set colsep... (1 Reply)
Discussion started by: avillanueva
1 Replies

7. Shell Programming and Scripting

create sql query

Hi Everyone, Can anyone pls help me out......with my requirement, i am struggling since 3 days. Please find the requirement below my file contains below data R1|Array/Network Resistor - VIP|V_RES_CLASS|V_MOUNT_FEATURE|SURFACE MOUNT|AND|8533.10.00.20|8533.10.00.20| R1|Array/Network Resistor... (9 Replies)
Discussion started by: jam_prasanna
9 Replies

8. Shell Programming and Scripting

Run SQL thru shell script: how to get a new line when run sql query?

Hi, this's Pom. I'm quite a new one for shell script but I have to do sql on shell script to query some information from database. I found a concern to get a new line...When I run my script, it retrieves all data as wondering but it's shown in one line :( What should I do? I'm not sure that... (2 Replies)
Discussion started by: Kapom
2 Replies

9. Programming

Getting error in sql query

Hi All , I have tried many times am getting syntax error on 'UNION' can anybody tell me ... INSERT INTO table1 ( Type , num_items , num_letters , total_value ) (select type='1', num_items, num_letters=count(*), total_value=sum(letter_value) from table2 where num_items = 1 (1 Reply)
Discussion started by: Venkatesh1
1 Replies

10. Shell Programming and Scripting

Column not allowed, when I am writing sql in UNIX

Please advice to rectify below error #!/bin/ksh X=$(sqlplus -s user/pass << EOSQL set serveroutput on; set heading off feedback off serveroutput on trimout on pagesize 0 INSERT INTO TEST(df) VALUES('a'); COMMIT; EXIT; EOSQL) echo $X echo $? ERROR at line 2: ORA-00984: column not... (1 Reply)
Discussion started by: mirwasim
1 Replies
CPANDB::Ticket(3pm)					User Contributed Perl Documentation				       CPANDB::Ticket(3pm)

NAME
CPANDB::Ticket - CPANDB class for the ticket table DESCRIPTION
TO BE COMPLETED METHODS
base # Returns 'CPANDB' my $namespace = CPANDB::Ticket->base; Normally you will only need to work directly with a table class, and only with one ORLite package. However, if for some reason you need to work with multiple ORLite packages at the same time without hardcoding the root namespace all the time, you can determine the root namespace from an object or table class with the "base" method. table # Returns 'ticket' print CPANDB::Ticket->table; While you should not need the name of table for any simple operations, from time to time you may need it programatically. If you do need it, you can use the "table" method to get the table name. load my $object = CPANDB::Ticket->load( $id ); If your table has single column primary key, a "load" method will be generated in the class. If there is no primary key, the method is not created. The "load" method provides a shortcut mechanism for fetching a single object based on the value of the primary key. However it should only be used for cases where your code trusts the record to already exists. It returns a "CPANDB::Ticket" object, or throws an exception if the object does not exist. select # Get all objects in list context my @list = CPANDB::Ticket->select; # Get a subset of objects in scalar context my $array_ref = CPANDB::Ticket->select( 'where id > ? order by id', 1000, ); The "select" method executes a typical SQL "SELECT" query on the ticket table. It takes an optional argument of a SQL phrase to be added after the "FROM ticket" section of the query, followed by variables to be bound to the placeholders in the SQL phrase. Any SQL that is compatible with SQLite can be used in the parameter. Returns a list of CPANDB::Ticket objects when called in list context, or a reference to an "ARRAY" of CPANDB::Ticket objects when called in scalar context. Throws an exception on error, typically directly from the DBI layer. iterate CPANDB::Ticket->iterate( sub { print $_->id . " "; } ); The "iterate" method enables the processing of large tables one record at a time without loading having to them all into memory in advance. This plays well to the strength of SQLite, allowing it to do the work of loading arbitrarily large stream of records from disk while retaining the full power of Perl when processing the records. The last argument to "iterate" must be a subroutine reference that will be called for each element in the list, with the object provided in the topic variable $_. This makes the "iterate" code fragment above functionally equivalent to the following, except with an O(1) memory cost instead of O(n). foreach ( CPANDB::Ticket->select ) { print $_->id . " "; } You can filter the list via SQL in the same way you can with "select". CPANDB::Ticket->iterate( 'order by ?', 'id', sub { print $_->id . " "; } ); You can also use it in raw form from the root namespace for better control. Using this form also allows for the use of arbitrarily complex queries, including joins. Instead of being objects, rows are provided as "ARRAY" references when used in this form. CPANDB->iterate( 'select name from ticket order by id', sub { print $_->[0] . " "; } ); count # How many objects are in the table my $rows = CPANDB::Ticket->count; # How many objects my $small = CPANDB::Ticket->count( 'where id > ?', 1000, ); The "count" method executes a "SELECT COUNT(*)" query on the ticket table. It takes an optional argument of a SQL phrase to be added after the "FROM ticket" section of the query, followed by variables to be bound to the placeholders in the SQL phrase. Any SQL that is compatible with SQLite can be used in the parameter. Returns the number of objects that match the condition. Throws an exception on error, typically directly from the DBI layer. ACCESSORS
id if ( $object->id ) { print "Object has been inserted "; } else { print "Object has not been inserted "; } Returns true, or throws an exception on error. REMAINING ACCESSORS TO BE COMPLETED SQL
The ticket table was originally created with the following SQL command. CREATE TABLE ticket ( id REAL NOT NULL, distribution TEXT NOT NULL, subject TEXT NOT NULL, status TEXT NOT NULL, severity TEXT NOT NULL, created TEXT NOT NULL, updated TEXT NOT NULL, PRIMARY KEY (id), FOREIGN KEY (distribution) REFERENCES distribution (distribution) ) SUPPORT
CPANDB::Ticket is part of the CPANDB API. See the documentation for CPANDB for more information. AUTHOR
Adam Kennedy <adamk@cpan.org> COPYRIGHT
Copyright 2009 - 2011 Adam Kennedy. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of the license can be found in the LICENSE file included with this module. perl v5.14.2 2011-11-25 CPANDB::Ticket(3pm)
All times are GMT -4. The time now is 11:29 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy