Need Sql for terda data database
Can any one help send me the sql for teradata database. for creating the variables. I need to create variables for Last month begin date and last month end date.
I am trying this tera data Sql this is for curent month date.
select cast(current_date as date) - (extract (day from cast(current_date as date)) - 1) + interval '1' month - 1
I need tera data sql for Last month begin date and last month end date. I searched various forums but could not get the answer. Any suggesstions please.
Similar Messages
-
Need SQL for below scenerio .
Hi Experts,
Consider an Order Table with the following table structure with some Sample Data:
ORDER_DAY
ORDER_ID
PRODUCT_ID
QUANTITY
PRICE
01-JUL-11
O1
P1
5
5
01-JUL-11
O2
P2
2
10
01-JUL-11
O3
P3
10
25
01-JUL-11
O4
P1
20
5
02-JUL-11
O5
P3
5
25
02-JUL-11
O6
P4
6
20
02-JUL-11
O7
P1
2
5
02-JUL-11
O8
P5
1
50
02-JUL-11
O9
P6
2
50
02-JUL-11
O10
P2
4
10
Need SQL to get all products that got sold both the days and the number of times the product is sold.
Desired output :
PRODUCT_ID
COUNT
P1
3
P2
2
P3
2
Thanks and Regards,
Sumanth KulkarniHi,
SumanthKulkarni wrote:
Hi
I tried below approach , but i didnt get desired output for P1
select count(s) a,product_id from
(select count(product_id) s,order_day ,product_id from orders group by order_day,product_id
order by product_id asc) t
group by product_id
having count(s) >1
Thanks and Regards
Sumanth Kulkarni
Run the sub-query by itself, and look at the results. You should see something like this:
S ORDER_DAY PRODUCT_ID
2 01-JUN-2011 P1
1 02-JUN-2011 P1
1 01-JUN-2011 P2
When you're computing the column a for the final output, do you want to count how many rows of this result set have product_id='P1'? That's what COUNT does, but I don't think that's what you want.
Do you want to add up the numbers in the S column? Then use SUM (s), not COUNT (s).
You could also do the whole job without a sub-query, like this:
SELECT COUNT (*) AS a
, product_id
FROM orders
GROUP BY product_id
HAVING COUNT (DISTINCT order_day) > 1 -
Need substitute for INT2 data type
Hi ,
Currently in my program..we have used a data type INT2.
The data type INT2 can hold only 5 characters at a time...with no commas in between and left Justified.
Now I got a problem that..the variable which is declard with INT2 was getting populated with more than 5 charaters.
So it gettin dump.
Now I need to change the data type of that variable.
I tried declaring with INT4..or Char...all these data types are nt left justified and also have commas in between.
Please suggest a data type..which can hold morethan 5 characters..left justified n no commas in between.
The problem..in declaring the variable as CHAR and manipulate it as required..is the variable which Im using in my program is called from a zstructure..
If I wanna modify it in the structure...then I need to change all the programs where the Zstructure is used..which I cant.
So request you to help me...is there any data type..which would replace INT2 with more than 5 characters in it and also no cammas in between and should be left justified.
Pls help.
Regards,
PriyaPure numeric fields (not c, not n, not string, etc.) DO NOT contain punctuation and decimals are implied. The obvious replacement for INT2 is to simply declare type I. If I needed decimals, I would convert to (15) type p decimals n. However, your output process is what is adding the punctuation....it's absolutely not embedded in a numeric field. You should read available helps (ABAP) on different data types.
-
Hi All,
what i need to do is to loop through a FM when some particular checkbox is checked for each date (it is in range format) entered through the selection screen by user.
I would like to just create one spool with all of the statements
now how to get this date from the selection screen with all these requirements??
useful answers will be awarded points..
thanksI have solved the problem now, it may no be the best way, quite bit complex. //thanks
-
Need suggestions for imporving data load performance via SQL Loader
Hi,
Our requirement is to load 512 (1 GB each) files in Oracle database.
We are using SQL loaders to load files into the DB (A partitioned table) and have tried almost all the possible options that come with sql loaders (Direct load path, parallel=true, multithreading=true, unrecoverable)
As the tables is growing bigger in size, each file load time is increasing (It started with 5 minutes per file and has reached 2 hours per 3 files now and is increasing with every batch- Note we are loading 3 files concurrently on the target table using the parallel = true oprion of sql loader)
Questions 1:
My problem is that somehow multithreading is not working for us (we have multi CPU server and have enabled multithreading=true). Could it be something to do with DB setting which might be hindering the data load to be done in multiple threads?
Question 2:
Would gathering stats on the target table and it's partitions help improve load performance ? I'm not sure if stats improve DML's, they would definitely improve sql queries. Any thoughts?
Question 3:
What would be the best strategy to gather stats on this table (which would end up having 512 GB data) ?
Question 4:
Do you think insertions in a partitioned table (with growing sizes) would have poor performance as compared to a non-partitioned table ?
Any other suggestions to improve performace are most welcome !!
Thanks,
Sachin
Edited by: Sachin Tiwari on Mar 13, 2013 6:29 AM2 hours to load just 3 GB of data seems unreasonable regardless of the SQL Loader settings. It seems likely to me that the problem is not with SQL Loader but somewhere else.
Have you generated a Statspack/ AWR/ ASH report to see where all that time is being spent? Are there triggers on the table? Are there bitmap indexes?
Is your table partitioned in a way that is designed to improve the efficiency of loads so that all the data from one file goes into one partition? Or is data from each file getting inserted into many different partitions.
Justin -
Hi Gurus
I have below situtation which need to be sorted out by SQL (10g version)
Below is the sample data.
Date Amt1 Amt2 Amt3 Totl
201009 10 10 10 30
201010 20 20 20 90
201011 30 20 10 150
Totl is the calculation field and remaining data is available in DB table say tab1. If you see logic of identifying Totl --> addition of Amt1,Amt2,Amt3 with Totl of prev month. For 201010 it is 20+20+20 =60 and this 60 will need to added to 201009 totl 30 and hence final sum is 90.
Please provide to resolve this.You need to do cumulative sum.
with t
as
select 201009 dt, 10 a1, 10 a2, 10 a3 from dual union all
select 201010, 20, 20, 20 from dual union all
select 201011, 30, 20, 10 from dual
select dt, a1, a2, a3, sum(a1+a2+a3) over(order by dt) tot
from t -
Need code for multi data insert..to table
Hi All,
I have input parameter data like ..
[email protected],b.gamil.com,c.gamil.com ...
and need to insert to table T_TABLE...LIKE
NAME
A
B
C
Please let me know how to implement...anbarasan wrote:
Hi All,
I have input parameter data like ..
[email protected],b.gamil.com,c.gamil.com ...
and need to insert to table T_TABLE...LIKE
NAME
A
B
C
Please let me know how to implement...Like this?
SQL> ed
Wrote file afiedt.buf
1 with t as
2 (select '[email protected],b.gamil.com,c.gamil.com ' txt from dual)
3 select upper(regexp_replace(REGEXP_SUBSTR(txt, '[^,]+', 1, level), '[@.](.*)$')) replace_str
4 from t
5* connect by level <= length(regexp_replace(txt, '[^,]*')) + 1
SQL> /
REPLACE_STR
A
B
CLogic for converting comma separated string to row borrowed from this post of Loknath Giri :
{message:id=10028213}
Edited by: Vivek L on 9 Mar, 2012 12:22 PM -
Need sql for the following requirement
EMP_DT EMP_TYPE emp_id
01/01/2011 3 546
01/03/2011 4 546
01/05/2011 3 546
01/08/2011 3 546
01/09/2011 3 546
01/10/2011 4 546
01/12/2011 3 546
01/14/2011 3 546
01/16/2011 3 546
01/18/2011 4 546
01/19/2011 3 546
Hi All,
I have a table with two columns(emp date and type where date is mm/dd/yyyy type tied to employee).
This data is inserted manually through online application. But behind the scenes I would like keep this date in the following fashion by a delete sql. When run the delete sql it should keep the data in following manner with employe type order 3,4,3,4,3,4 and so on. There shouldn't be any 3 empolyee type rows continuosly. Also when delete the data it should keep the smaller date out of three same employee type dates. example 01/12/2011,01/14/2011,01/16/2011 ---> we will keep the row 01/12/2011 and delete two other dates because they are same type of dates(3).
EMP_DT EMP_TYPE emp_id
01/01/2011 3 546
01/03/2011 4 546
01/05/2011 3 546
01/10/2011 4 546
01/12/2011 3 546
01/18/2011 4 546
01/19/2011 3 546Hi,
So, on each row, you need to know what the value of emp_type was on the previous row. That sounds like a job for LAG.
Here's one way to do that:
WITH got_prev_emp_type AS
SELECT emp_dt, emp_type, emp_id
, LAG (emp_type, 1, -1) OVER ( PARTITION BY emp_id -- Just guessing
ORDER BY emp_dt
) AS prev_emp_type
FROM a_table
-- WHERE ... -- If you need any filtering, put it here
SELECT emp_dt, emp_type, emp_id
FROM got_prev_emp_type
WHERE emp_type != 3
OR prev_emp_type != 3
ORDER BY emp_id
, emp_dt
;This assumes that emp_dt is a DATE (or a TIMESTAMP). If it has some other dattype, convert it to a DATE.
"DELETE" means "permanently remove rows from a table." Is that what you want, or do you just want to exclude some rows from a result set? The query above doesn't actually change the table. If that's what you want to do, you can use the query above as a sub-query in hte WHERE clause of a DELETE statement.
DELETE FROM table_a
WHERE (emp_dt, ,emp_type, emp_id) -- Just guessing
NOT IN (
WITH got_prev_emp_type AS
);This assumes that emp_dt, demp_type and demp_id are never NULL.
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables, and also post the results you want from that data.
If you're asking about a DML statement, such as DELETE, the sample data will be the contents of the table(s) before the DML, and the results will be state of the changed table(s) when everything is finished.
Explain, using specific examples, how you get those results from that data.
Always say which version of Oracle you're using. All the code I psoted above assumes you have Oracle 9.1 or higher. -
SQL Developer create wrong SQL for creation of Database link
Hi,
I tried to create Database link to another machine through SQL Developer. and I got error message saying "Sql not properly ended" or similar.
I copy-paste the sql to sqlplus shell and I found that the problem came from password part of database link so the generated from SQL Plus is something like:
SQL> CREATE DATABASE LINK mytest CONNECT TO anotherDB IDENTIFIED BY 1234 USING 'OtherServiceName';
but it should be
SQL> CREATE DATABASE LINK mytest CONNECT TO anotherDB IDENTIFIED BY "1234" USING 'OtherServiceName';
so if I type in the password field
"1234" which is ****** /6 chars/ the database link was created correctly.
Could you check and fix this in next release of the SQL Developer?
Otherwise the Application is very good and far ahead from TORA :)Thanks, I didn't notice that for passwords. So it's most definately my problem that the SQL Developer . :)
Thank you for clarification!
Offtopic: I am searching for DB Comparison tool which could compare 2 schemas and return me the differences and the sync script. Do you know any /free if possible/? There is such thing in TOAD but I am on Linux and I prefer to use something else. :)
Thank you in advance -
Need Logic for Inserting data into table from another table
Hi,
Could you please give me some logic on below:
TABLE_A has columns A,B,C,D
What i did
==========
Created new table
TABLE_1_A with columns A1,A2,B1,B2,B3
Requirement
===========
I should populate columns A1,A2 (table TABLE_1_A) with the data from column A (table TABLE_A)
& simillarly populate columns B1,B2 with the data from B.
the data is huge in the table_a.
Database: 10g
Thanks.Hi,
Here's one way:
INSERT INTO table_1_a
(a1, a2, b1, b2)
SELECT a, a, b, b
FROM table_a
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and also post the results you want from that data.
If you're asking about a DML statement, such as INSERT, the sample data will be the contents of the table before the DML, and the results will be state of the changed table(s) when everything is finished.
Explain, using specific examples, how you get those results from that data.
See the forum FAQ {message:id=9360002} -
Need help for SRM Data Extraction into BI-7
Hi Experts,
I am looking for help regarding SRM DataSource Extraction to BW. I am working on BW project and need to extract data from SRM Data Source 0BBP_TD_CONTR_2 and 0SRM_TD_PRO. I need to know about the extraction process from SRM. Is there a tool available like LO Cockpit in SRM for extraction and how can we manage the delta in it. Or i can use the T-code RSA5 for that and follow the normal process. If I can get some documentation that can give me an idea for data extraction and delta management in SRM that would be appreciated. Any kind of help will be welcome.
Thanks in Advance.SRM doesn't use kind of "cockpit" LO-like in ECC.
Overall picture:
http://help.sap.com/saphelp_srm40/helpdata/en/b3/cb7b401c976d1de10000000a1550b0/content.htm
If you setup data flows accordign Business Content of SRM:
http://help.sap.com/saphelp_nw2004s/helpdata/en/3a/7aeb3cad744026e10000000a11405a/frameset.htm
Then just perform an init load and schedule the deltas. -
Need query for refresh test database.
Hi,
I want refresh production database to test database refresh using expdp dumpfile. Please provide steps this is the requirement
This request is to refresh the Tecnomatix test database MFEM which is
on the NATEST server wnmcdwtk.natest.gm.com. This database needs to
be refreshed using an Oracle full backup dump file from the Tecnomatix
production database MFEP which runs on the production NAENG server
wnmcdds8.naeng.gm.com. The MFEM and MFEP databases are both at Oracle
v10.2.0.4.Hi,
You have posted to the wrong section of the forum. This forum us for Berkeley DB.
Regards,
Alex Gorrod
Oracle Berkeley DB -
Need help for HR data migration
Hi Experts,
I need a help that i want to do data migration for PA30 and PP01 transactions.so if any std bapi for upload the data or bdc programs you have means let me know for further process.if early it is good for me.
Thanks,
DeesanthYou can use the standard batch program RPUSTD00. Also you can use the function module HR_INFOTYPE_OPERATION.
Hope this is helpful.
Thanks,
Pavan -
Hi,
I want a count of def as well as starting day of the week based on FDate week wise.
I have build a case structure starting from beginning to end of the week. But it is not working.
Please let me know a way where i can get a count of def for each week as well as starting day of the week.
For the WHERE clause i have a given a date range but it should be for the last 20 weeks.
SELECT FDate, count(def)
from Table
WHERE FDate > = '2008-03-17' and FDate <= '2008-08-07'
group by FDate
order by
case when FDate >= '2008-03-17' and FDate <= '2008-03-23' Then '2008-03-17'
when FDate >= '2008-03-24' and FDate <= '2008-03-30' Then '2008-03-24'
when --------
when --------
end
Please help.
Thanks.Hi,
While you could use a 20-pronged CASE statement, it's much eachier to use
GROUP BY TRUNC (fdate, 'IW')
TRUNC (fdate, 'IW') returns the DATE of the last Monday (12 midnight) that was on or before fdate. ("IW" stands for Iinternational Standards Organization Week.) It's an easy way to map an entire week into one value, and, unlike the 'D' format that Kevin and Guido mentioned earlier, it works the same regardless of you NLS settings.
What if you need to combine things by week, but you want to consider Sunday the start of the week? That's 1 day earlier than the ISO Week, and instead of
TRUNC (fdate, 'IW') you would use
TRUNC (fdate + 1, 'IW') - 1. -
Hi All,
There is a table TASK with columns TASK_NAME,IS_TASK. IS_TASK column has only two distinct values 0(means PHASE) and 1(means TASK). The hierarchy is a PHASE can have one or more TASKS, but the name of PHASE and TASK is in TASK_NAME column and separated only by IS_TASK columns value. The result set I need is PHASE_NAME,TASK_NAME separately.
Please help me.
Thanks & RegardsPlease consider the following when you post a question.
1. New features keep coming in every oracle version so please provide Your Oracle DB Version to get the best possible answer.
You can use the following query and do a copy past of the output.
select * from v$version 2. This forum has a very good Search Feature. Please use that before posting your question. Because for most of the questions
that are asked the answer is already there.
3. We dont know your DB structure or How your Data is. So you need to let us know. The best way would be to give some sample data like this.
I have the following table called sales
with sales
as
select 1 sales_id, 1 prod_id, 1001 inv_num, 120 qty from dual
union all
select 2 sales_id, 1 prod_id, 1002 inv_num, 25 qty from dual
select *
from sales 4. Rather than telling what you want in words its more easier when you give your expected output.
For example in the above sales table, I want to know the total quantity and number of invoice for each product.
The output should look like this
Prod_id sum_qty count_inv
1 145 2 5. When ever you get an error message post the entire error message. With the Error Number, The message and the Line number.
6. Next thing is a very important thing to remember. Please post only well formatted code. Unformatted code is very hard to read.
Your code format gets lost when you post it in the Oracle Forum. So in order to preserve it you need to
use the {noformat}{noformat} tags.
The usage of the tag is like this.
<place your code here>\
7. If you are posting a *Performance Related Question*. Please read
{thread:id=501834} and {thread:id=863295}.
Following those guide will be very helpful.
8. Please keep in mind that this is a public forum. Here No question is URGENT.
So use of words like *URGENT* or *ASAP* (As Soon As Possible) are considered to be rude.
Maybe you are looking for
-
Open View Sets are not closing when reports close. Is there a way to force close view sets without bouncing the BAM-Server? I running v11.1.1.3 on WLS 10.3
-
Updating and syncing issues from iPhone to iPad
I have two issues. I just got new iPhone and after creating an iCloud account all my contacts will only appears numbers on my phone (no names attached to the contacts) and now that updated my iPad to io5 nothing will sync with my iPhone. I checked m
-
Modify extension of txt file under labview
I've got a.log file or .txt file than i copy in new directory and i would like to use this file under excel, but I don't know how can i change the extension under Labview??? I hope than you understand me. Thank you,
-
AI/PDF/... - SWF with *original* images?
Using Xara, I have created a vector illustration. However, when exporting it to SWF, Xara re-rasterizes all images to a common resolution. I do not want that! I want to have the images untouched, because later I want to zoom in on them (in Prezi). I
-
I am facing an issue " Denied connection per minute from one ip address" why this error occur and how to resolve it? is it really harmful for my TMG Server or not?? Error Description: The number of denied connections from the source IP address 10.0.0