sql guide needed


 
Thread Tools Search this Thread
Top Forums Programming sql guide needed
# 1  
Old 10-02-2012
sql guide needed

Code:
SQL> select
  2  distinct qc_m|| ',' ||
  3  to_char(logon_dt, 'YYYY-MM-DD HH24:MI:SS')|| ',' ||
  4  CASE WHEN logon_dt IS NOT NULL THEN 'LOGON' ELSE 'LOGOFF' END
  5  from qc_ct2 qc left join v_tls_equipment_logon tls on qc.qc_m=tls.equipment_id where
  6  qc.terminal_c='T'and tls.USER_TYPE_C='1' and tls.site_c='C' order by 1 asc;

result:
26 rows selected.

I have 28 records in:
Code:
select qc_m from qc_ct2 where terminal_c='T';

what is it that I needed to keep the 28 records without been filter away by line 6 statement... but then, I need the line 6 statement to meet the critera....

---------- Post updated at 02:54 PM ---------- Previous update was at 02:25 PM ----------

Code:
(USER_TYPE_C='1' or (USER_TYPE_C!='1'and logon_dt IS NULL))

I tried this but it gives me duplicate records when it meets both condition =/

---------- Post updated at 02:58 PM ---------- Previous update was at 02:54 PM ----------

Code:
case when(USER_TYPE_C='1' or (USER_TYPE_C!='1'and logon_dt IS NULL))
then USER_TYPE_C='1' 
end

I wish to implement this aft where can anyone gimme an approach?

---------- Post updated at 03:05 PM ---------- Previous update was at 02:58 PM ----------

Code:
and (USER_TYPE_C='1'or (USER_TYPE_C!='1'and logon_dt IS NULL))
(case when(USER_TYPE_C='1' and (USER_TYPE_C!='1'and logon_dt IS NULL))
then USER_TYPE_C='1' 
end)

any tips to rephrase this line?

---------- Post updated at 03:28 PM ---------- Previous update was at 03:05 PM ----------

Code:
select qc_m from qc_ct2 qc left join v_tls_equipment_logon tls on qc.qc_m=tls.equipment_id 
where 
case when (USER_TYPE_C='1' and (USER_TYPE_C!='1' and logon_dt IS NULL))
then USER_TYPE_C='1'
else (USER_TYPE_C='1' or (USER_TYPE_C!='1' and logon_dt IS NULL)
end
and terminal_c='T'
and site_c='C' order by 1 asc;

thinking of this atm Smilie but still cant work
# 2  
Old 10-03-2012
It's very difficult to figure out what you are trying to do here. For questions like yours, the best thing to do is:

(1) Post the data in your tables. You do not have to show us actual data; you could just show mock-up/dummy data. Keep it short, say, 5 to 10 rows.

(2) Post the "create table" and "insert into table" statements for your mock-up data. It will help us with the setup in a test schema.

(3) Mention what you want to see as the output of your query.

tyler_durden
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Storing multiple sql queries output into variable by running sql command only once

Hi All, I want to run multiple sql queries and store the data in variable but i want to use sql command only once. Is there a way without running sql command twice and storing.Please advise. Eg : Select 'Query 1 output' from dual; Select 'Query 2 output' from dual; I want to... (3 Replies)
Discussion started by: Rokkesh
3 Replies

2. Shell Programming and Scripting

Code needed to get sql queries

Hi i need code to get sql queries through a shell script for a text file input which contain the service ids iputfile I-H-2048-10GB-M I-H-4096-12GB-M I-H-2048-p1000-M the code should contain below queries among which service_id is replacable with value from input file. ... (4 Replies)
Discussion started by: surender reddy
4 Replies

3. Shell Programming and Scripting

guide needed to combine 2 variables

readNOW=$(date +"%Y%m%d%H%M") read readTerminal #input B terminalc=$readTerminal echo eqpt_list_QC_$terminalcT_$readNOW how to get display result it: eqpt_list_QC_BT_201209121530 (2 Replies)
Discussion started by: ment0smintz
2 Replies

4. Shell Programming and Scripting

Guidance needed for a typical shell script with sql query

Hi , I have a txt file with contents like: 1234 2345 3456 7891 I need to write a script which takes input file as txt file..run a sql query for that number and place the output of query in another file.. select * from bus_event where acct_nbr='1234'( from input txt file) the query... (20 Replies)
Discussion started by: Rajesh Putnala
20 Replies

5. Shell Programming and Scripting

Help needed with KSH and SQL

Hi All I have a problem with one of my scripts which checks for he status of an Oracle database. Here's the script: #!/bin/ksh sqlplus -s '/nolog' <<EOF connect / as sysdba set heading off spool db_status.txt select OPEN_MODE from v\$database / exit EOF db_status=$(more... (4 Replies)
Discussion started by: huskie69
4 Replies

6. Shell Programming and Scripting

Confirmation needed while running the sql's

Hi, I need confirmation whether the same functionality exists when running the sql's. For ex. let us consider there exists a sql file with name june.When running in sql mode does: @june.sql and start june.sql does the same functionality. Someone help me. Thanks Ashok. (1 Reply)
Discussion started by: Ashok_oct22
1 Replies

7. Shell Programming and Scripting

Help needed in script and sql file

Hi all, I have a script which takes in sqlfile as argument and executes the sql execSqlFile() { sqlFile=$1 sqlplus -S $DBLOG/$DBPWD@$DBSVR < $sqlFile } This works fine if the sql file is plain, simple and pre-defined statment. But i want to have a sql file which itself... (2 Replies)
Discussion started by: jakSun8
2 Replies

8. Shell Programming and Scripting

Script needed to FTP a file from sql report to unix server

Hi All, I have a Sqlplus report which will create a file. I need a FTP Script that will be executed inside the Sqlplus Report to FTP the report output file to unix server. Thanks, Previn (0 Replies)
Discussion started by: vprevin
0 Replies
Login or Register to Ask a Question