Query in sql server2000
Hi,
Table: dbo.test
Tid TValue
Tdate
1001 300
05/05/2013
1002 400
05/05/2013
1001 800
06/05/2013
1002 600
06/05/2013
Output
Tid TMonth
Monthvalue
1001 May-June
500
1002 May-June
200
Im working on sql server 2000. I need query in sql server 2000.
Please do the needful.
Thanks, but this is not correct query.
Please consider previous value for the below example.
Tid TValue
Tdate
1002
400
05/05/2013
1002 800
06/05/2013
1002 900
07/05/2013
1002
1100
08/05/2013
The following output should be displayed using sql server 2000
OutPut:
1002
May-June 400
1002
June-July 100
1002
July-Aug 200
Similar Messages
-
SQL query (pl/sql function body returning query) performance issue
I create my report in building my sql instruction with ( SQL Query pl/sql function body returning sql query );
My report take more than 20 seconds however if i did a cut and paste with the sql code in TOAD the same sql take 1 second.
To try to discover the source of the problem; i take the sql generated by the function and i create another report ( sql query ) this new report take 2 seconds.
My query is very big 25,000 characters with database link.
What is the difference between SQL-quey and sql-query(pl/sql function body returning sql query)
Thanks
MarcMarc,
Firstly...don't compare the timings from Toad, since often Toad only fetches the first few records for you (i.e. it pages them).
Secondly....the database link could be a factor here, but without seeing your query it's too hard to say.
Can you post the query somewhere (on a webserver say)? -
Different output of same query in SQL Server and Oracle
I have two tables table1 and table2
--table1 has two columns c1 int and c2 varchar. there are not constraints added in it. it has data as given below
c1 c2
6 d
5 j
102 g
4 g
103 f
3 h
501 j
1 g
601 n
2 m
--table2 has only one column c1 int. there are not constraints added in it. it has data as given below
c1
6
1
4
3
2
now when i run below given query in sql server and oracle it gives me different result
select *
from table1
inner join (SELECT ROW_NUMBER() OVER (order by c1 ASC) AS c1 from table2) table2 on table2.c1=table1.c1
sql server output
c1 c2 c1
1 g 1
2 m 2
3 h 3
4 g 4
5 j 5
oracle output
C1 C2 C1
5 j 5
4 g 4
3 h 3
1 g 1
2 m 2
If you notice the first column in both output. It is sorted in sql server and not in oracle.
Why it is behaving differently in oracle? Is there any way I can solve this in oracle?
Thanks,
JigsIt is NOT behaving "differently" in Oracle; you just haven't specified an order that you expect your results to be in, so you're going to get output in whatever order the database fancies displaying it (ie. no guarenteed order). This is an artifact of how the database chooses to put together the data, and different databases (or even datasets within the same database) can and most likely will behave differently.
Even SQL Server won't guarentee to always get your data in an ordered fashion if you exclude the order by clause, even if you think it has always output the data in an ordered fashion.
Your solution is to add an order by clause, in BOTH databases, to force the order of the output data. -
SQL Query (pl/sql function body returning Sql query)
Hi All,
I have created a region of "SQL Query (pl/sql function body returning Sql query)" type and it is working fine , but when I am migrating(export /import) this application from development to systest environment ,
It gives error for this region :
Error ERR-1101 Unable to process function body returning query.
OK
ORA-06550: line 1, column 52: PLS-00306: wrong number or types of arguments in call to 'FU_TRADE_REPORT_QUERY' ORA-06550: line 1, column 45: PL/SQL: Statement ignored
Any pointer ...why this is happening.
Thanks
DikshitIf your function is a stored function that is called from within APEX (function body not coded into the app itself), have you made sure that the function has been created and compiles ok prior to installing your apex app.
If there are some dependency issues between other PL/SQL units or database objects that are causing your function not to be compiled, you apex install will fail as you are trying to reference an uncompelled bit of pl/sql.
Let me know how you get on
Regards
Duncan -
SQL Query(PL/SQL Function Returning SQL Query)
I am trying to write a dynamic report using SQL Query(PL/SQL Function Returning SQL Query).
I can get the report to run but I need to concatinate some columns into one, seperated by a comma or a dash.
I have tried select *****||','||***** alias
also select *****||'-'||***** alias
but I always get an error.
Is there a way of doing this please
GusThis is my full query
declare
v_query varchar2(4000);
begin
if :P63_TRAN_INFO = 2 THEN
v_query := 'select
A.FILENR,
A.EXERCISENAME,
A.STARTDATE,
A.ENDDATE,
A.UNIT,
A.ACCADDRESSES, B.ADDRESS, B.ADDRESS_1, B.POST_CODE, B.TOWN,
A.EXERCISEAREAS,
A.TOTALVEHICLES,
A.TOTALTROOPS+A.RNTOTALTROOPS+A.RAFTOTALTROOPS TOTALTROOPS,
A.CAR, A.MINIBUS, A.HGV,
A.NAMERANK, A.ADDRESS, A.ADDRESSI, A.ADDRESSII, A.POSTCODE,
A.TRANSIT,
A.INFOONLY
from BFLOG_AT A, BFLOG_ACCADDRESS B
WHERE A.ACCADDRESSES = B.NAME
AND A.STARTDATE >= :P63_START_DATE
AND A.ENDDATE <= :P63_END_DATE
AND A.AUTHORISED = 1
AND A.INFOONLY = 1' ;
END IF;
RETURN v_query;
END;
This query runs ok, but if I try changing it to the code below with fields concatinated, then it fails
declare
v_query varchar2(4000);
begin
if :P63_TRAN_INFO = 2 THEN
v_query := 'select
A.FILENR,
A.EXERCISENAME,
A.STARTDATE,
A.ENDDATE,
A.UNIT,
A.ACCADDRESSES||','||B.ADDRESS||','||B.ADDRESS_1||','||B.POST_CODE||','||B.TOWN ADDRESS,
A.EXERCISEAREAS,
A.TOTALVEHICLES,
A.TOTALTROOPS+A.RNTOTALTROOPS+A.RAFTOTALTROOPS TOTALTROOPS,
A.CAR, A.MINIBUS, A.HGV,
A.NAMERANK, A.ADDRESS, A.ADDRESSI, A.ADDRESSII, A.POSTCODE,
A.TRANSIT,
A.INFOONLY
from BFLOG_AT A, BFLOG_ACCADDRESS B
WHERE A.ACCADDRESSES = B.NAME
AND A.STARTDATE >= :P63_START_DATE
AND A.ENDDATE <= :P63_END_DATE
--AND (A.EXERCISEAREAS LIKE "GAP, OA, OAL")
--OR (A.EXERCISEAREAS LIKE "Harz")
AND A.AUTHORISED = 1
AND A.INFOONLY = 1' ;
END IF;
RETURN v_query;
END;
Cheers
Gus -
SQL Query ( PL/SQL function body returning query ) page
Hello Friends,
I have a page with type SQL Query ( PL/SQL function body returning query ).
I have written a pl/sql block that returns a sql query - select statment.
Some times i am getting no data found error - does it got to do with the variable that stores the query .
=======================
ORA-06502: PL/SQL: numeric or value error: character string buffer too small
Error ERR-1101 Unable to process function body returning query.
OK
=====================
When the query is returned with records where exactly the records are stored is it in the variable declared in pl/sql block or with the Oracle Apex implicit cursor.
Here's the pl/sql block ..
The query is generated while the user is navigating through pages ..
====================
declare
l_return_stmt varchar2(32767);
l_select varchar2(32000);
l_from varchar2(32000);
l_where varchar2(32000);
l_order_by varchar2(32000);
l_stmt_recordcount varchar2(32000);
l_recordcount number ;
begin
l_select := 'select '||:P10_VARLIST1||:P10_VARLIST2||:P10_VARLIST3
||:P10_VARLIST4||:P10_VARLIST5;
l_from := ' from '||:P10_RELATION;
if length(:P10_WHERE) > 0 then
l_where := ' where '||:P10_WHERE;
else
l_where := '';
end if;
if length(:P10_ORDER_BY) > 0 then
l_order_by := ' order by '||:P10_ORDER_BY;
else
l_order_by := '';
end if;
l_return_stmt := l_select||l_from||l_where||l_order_by;
:P10_STMT := l_return_stmt;
return l_return_stmt;
end;
=============================
Appreciate your help in this regard.
thanks/kumar
Edited by: kumar73 on Apr 22, 2010 6:38 AMIt looks like the query string you are trying to pass back exceeds the 32K limit for a varchar. Where this is happening is kind of difficult to tell as it could be any number of points, and also depends on what you are passing into the process via page items.
I would first try to establish what combination of page items causes this error to occur. Then, starting from the bottom and working your way backwards, I would start 'switching off' some of the items you use to build your query until it breaks again, thus establishing which part is leading to the error.
Also, I'm not sure what :P10_STMT is doing (are you maybe using this for visiblity of the query created)?
It looks like the query string you are trying to pass back exceeds the 32K limit for a varchar. Where this is happening is kind of difficult to tell as it could be any number of points, and also depends on what you are passing into the process via page items.
I would first try to establish what combination of page items causes this error to occur. then, starting from the bottom and working your way backwards, I would start 'switching off' some of the items you use to build your query until it breaks again, thus establishing which part is leading to the error.
Also, I'm not sure what :P10_STMT is doing (are you maybe using this for visiblity of the query created)? -
SQL Query (PL/SQL function body returning SQL query) when using to_char
we are trying to build a report page of Type SQL Query (PL/SQL function body returning SQL query).
our query is so simple, we need to extract the month from the recording_date column.
declare
l_query varchar2(1000);
begin
l_query:='select to_char(recording_date,'MM')from re_productive';
return l_query;
end;
but we are having the following problem for this query
Function returning SQL query: Query cannot be parsed within the Builder. If you believe your query is syntactically correct, check the generic columns checkbox below the region source to proceed without parsing.
(ORA-06550: line 4, column 42: PLS-00103: Encountered the symbol "MON" when expecting one of the following: . ( * @ % & = - + ; < / > at in is mod remainder not rem <> or != or ~= >= <= <> and or like between || multiset member SUBMULTISET_ The symbol ". was inserted before "MON" to continue.)
Notes:
1-the query is correct and it was tested under Toad and SQL Plus.
2- we tried Use Generic Column Names (parse query at runtime only) option but we get the same problem.
any quick help please.Hi
You haven't escaped your quotes in the string. Try this...
DECLARE
l_query VARCHAR2(32767);
BEGIN
l_query:= 'select to_char(recording_date,''MM'') from re_productive';
RETURN l_query;
END;Cheers
Ben -
SQL Query (PL/SQL Function Body returning SQL query) doesn't return any row
I have a region with the following type:
SQL Query (PL/SQL Function Body returning SQL query).
In a search screen the users can enter different numbers, separated by an ENTER.
I want to check these numbers by replacing the ENTER, which is CHR(13) || CHR(10) I believe, with commas. And then I can use it like this: POD IN (<<text>>).
It's something like this:
If (:P30_POD Is Not Null) Then
v_where := v_where || v_condition || 'POD IN (''''''''||REPLACE(''' || :P30_POD || ''', CHR(13) || CHR(10), '','')||'''''''''')';
v_condition := ' AND ';
End If;
But the query doesn't return any rows.
I tried to reproduce it in Toad:
select * from asx_worklistitem
where
POD IN (''''||REPLACE('541449200000171813'||CHR(13) || CHR(10)||'541449206006341366', CHR(13) || CHR(10), ''',''')||'''')
==> This is the query that does't return any rows
select (''''||REPLACE('541449200000171813'||CHR(13) || CHR(10)||'541449206006341366', CHR(13) || CHR(10), ''',''')||'''')
from dual;
==> This returns '541449200000171813','541449206006341366'
select * from asx_worklistitem
where pod in ('541449200000171813','541449206006341366');
==> and when I copy/paste this in the above query, it does return my rows.
So why does my first query doesn't work?
Doe anyone have any idea?
Kind regards,
Geert
Message was edited by:
ZorryThanks for the help.
I made it work, but via the following code:
If (:P30_POD Is Not Null) Then
v_pods := REPLACE(:P30_POD, CHR(13) || CHR(10));
v_where := v_where || v_condition || 'POD IN (';
v_counter := 1;
WHILE (v_counter < LENGTH(v_pods)) LOOP
v_pod := SUBSTR(v_pods, v_counter, 18);
IF (v_counter <> 1) THEN
v_where := v_where || ',';
END IF;
v_where := v_where || '''' || v_pod || '''';
v_counter := v_counter + 18;
END LOOP;
v_where := v_where || ')';
v_condition := ' AND ';
End If;But now I want to make an update of all the records that correspond to this search criteria. I can give in a status via a dropdownlist and that I want to update all the records that correspond to one of these POD's with that status.
For a region you can build an SQL query via PL/SQL, but for a process you only have a PL/SQL block. Is the only way to update all these records by making a loop and make an update for every POD that is specified.
Because I think this will have a lot of overhead.
I would like to make something like a multi row update in an updateable report, but I want to specify the status from somewhere else. Is this possible? -
How to get exact query of sql in oracle?
Hi all,
Hope doing well,
sir i was using one query of sql that is here:
Declare @nshiftmax datetime
set @nshiftmax=convert(time,DATEADD(N,1439,0))
print @nshiftmax
so it is retreiving the result 1/1/1900 11:59 p.m
and one more query is there
Declare @nshiftmax datetime
set @nshiftmax=convert(time,DATEADD(N,0,0))
print @nshiftmax
so it is retreiving the result 1/1/1900 12:00 a.m
how to same result in oracle query.
thanks in advance.952646 wrote:
Hi all,
Hope doing well,
sir i was using one query of sql that is here:
You mean you have these statements in SQL Server?
Please remember that SQL is an access language for relational databases. It is used by all of the major rdbms products. "SQL Server" is the name of Microsoft's rdbms product. Do not let Microsoft's marketing flaks lull you into thinking SQL = SQL Server.
Declare @nshiftmax datetime
set @nshiftmax=convert(time,DATEADD(N,1439,0))
print @nshiftmax
so it is retreiving the result 1/1/1900 11:59 p.m
and one more query is there
Declare @nshiftmax datetime
set @nshiftmax=convert(time,DATEADD(N,0,0))
print @nshiftmax
so it is retreiving the result 1/1/1900 12:00 a.m
how to same result in oracle query.
thanks in advance. -
Procedure output like a query in SQL developer?
Hi!
How can a PL procedure create output like a query in SQL developer?
This block
begin
for record in (
select * from my_db
loop
dbms_output.put_line(record.name ' ' || record.address)
end loop;
end;
would print a of names and adresses in my_db. However, output sent to a query result window which would be the result of
select name,address from my_db;
How could I make the PL block behave the same way as the SQL query, i.e. present its output in a query result window?Welcome to the forum!
Please provide your 4 digit Oracle version (result of SELECT * FROM V$VERSION) wheneve you ask a question.
Do you mean query a procedure as if it were a table?
You can do that with a pipelined function. Here is sample code you can test using the SCOTT schema
-- type to match emp record
create or replace type emp_scalar_type as object
(EMPNO NUMBER(4) ,
ENAME VARCHAR2(10),
JOB VARCHAR2(9),
MGR NUMBER(4),
HIREDATE DATE,
SAL NUMBER(7, 2),
COMM NUMBER(7, 2),
DEPTNO NUMBER(2)
-- table of emp records
create or replace type emp_table_type as table of emp_scalar_type
-- pipelined function
create or replace function get_emp( p_deptno in number )
return emp_table_type
PIPELINED
as
TYPE EmpCurTyp IS REF CURSOR RETURN emp%ROWTYPE;
emp_cv EmpCurTyp;
l_rec emp%rowtype;
begin
open emp_cv for select * from emp where deptno = p_deptno;
loop
fetch emp_cv into l_rec;
exit when (emp_cv%notfound);
pipe row( emp_scalar_type( l_rec.empno, LOWER(l_rec.ename),
l_rec.job, l_rec.mgr, l_rec.hiredate, l_rec.sal, l_rec.comm, l_rec.deptno ) );
end loop;
return;
end;
/Then you can query the function as if it were a table
select * from table(get_emp(20))Is that what you were looking for? -
My coldfusion service crashes intermitantly and when I check
the application logs the error that I see for the time frame is the
one below. Does anyone know where I might begain to solve this?
Thanks!
Error Executing Database
Query.coldfusion.sql.DatabaseConnectionException: Timed out trying
to establish connection The specific sequence of files included or
processed is: E:\wwwroot\lifeworks\default.cfmI'm no expert, but thought I would try to be helpful.
I was getting this same error on a regular basis.
The short term fix was to restart the ODBC server service.
The long term fix was twofold:
1. I recreated the ODBC connection in ColdFusion
Administrator to use the system connection (I was using the SA and
PW for login).
2. I created a second user ODBC connection as well as the
system one under ODBC in Windows Server 2003.
I haven't had the problem since.
I also read a pretty good set of "stuff" to try from the help
area:
http://www.adobe.com/cfusion/knowledgebase/index.cfm?id=tn_17277
Hope this helps. -
Help with translating SQL query from SQL Server syntax to Oracle syntax
Hi,
is it someone that can help me translate following SQL query from SQL Server syntax to Oracle syntax.
SELECT ID,
[LMT(MTR)] = MAX(case when TYPE = 'LMT' then VALUE end),
[AAD(KGM)] = MAX(case when TYPE = 'AAD' then VALUE end),
[VOL(MTQ)] = MAX(case when TYPE = 'VOL' then VALUE end)
FROM yourtable
GROUP BY ID
Your help is highly appreciated, thanks in advance.Like this,
SELECT ID,
MAX(case when TYPE = 'LMT' then VALUE end) LMT_MTR,
MAX(case when TYPE = 'AAD' then VALUE end) AAD_KGM ,
MAX(case when TYPE = 'VOL' then VALUE end) VOL_MTQ
FROM yourtable
GROUP BY ID-Arun -
Code to run a query in SQL from Access with pass through query
I have a query in SQL Server 2008:
[Auto Null Up Date].sql. I want to run this query from Access 2007 using a Pass Through Query. What is the command/code to run this query from Access? I have used Pass Through Queries but never in this capacity so I am somewhat lost. I have
already established the OBDC link and tested.Naomi,
Here are a few lines of the SQLCMD code in the [Auto Null Update].sql query:
USE [Archive Master]
Go
:r "\\10.200.1.60\c$\Users\bkreft\My Documents\SQL Server Management Studio\Projects\Null BackPress 2 update.sql"
GO
:r "\\10.200.1.60\c$\Users\bkreft\My Documents\SQL Server Management Studio\Projects\Null CHWR 3 update.sql"
GO
:r "\\10.200.1.60\c$\Users\bkreft\My Documents\SQL Server Management Studio\Projects\Null CHWR 4 update.sql"
When this code is pasted into a Create Procedure, (the USE [Archive Master] is not used), the procedure will run, but once saved here is what is left of the procedure once I attempt to modify:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:
<Author,,Name>
-- Create date: <Create Date,,>
-- Description:
<Description,,>
-- =============================================
Create PROCEDURE [dbo].[NullTest2]
AS -
Hello,
I've set up a region definition of type "SQL Query(PL/SQL function body return SQL query). In my query I make use of an "in" condition. When I populate :P755_INC_BARG_UNIT with a value of 0F (no quotes), I get the correct count. However, when I set :P755_INC_BARG_UNIT to 0F, 0E I get an invalid count. What do I have to set the page item to?
When running the query in TOAD, and setting :P755_INC_BARG_UNIT to the string inside the brackets (0F, 0E) I get the proper count.
The code I use is shown below. Any help would be appreciated,
Alex.
DECLARE
v_sql VARCHAR2(32767);
BEGIN
SELECT count(*) "cnts",
''Faculty data file IDs missing in appt table'' "err_type"
FROM hradmin.et_faculty_salary fs left outer join
hradmin.appointments appt
ON trim(fs.empl_id) = appt.emp_emp
and appt.ear_activ <> ''Z''
and appt.ear_type = ''F''
and (appt.ear_class in (''A'',''B'',''C'',''D''))
and appt.ear_bargunit in ( :P755_INC_BARG_UNIT )
WHERE appt.emp_emp is null
RETURN v_sql;
END;Alex,
try something like:
DECLARE
v_sql VARCHAR2(32767);
BEGIN
v_sql := <YOUR_SQL_STATEMENT_WITH_P755_INC_BARG_UNIT_IN_IT>;
v_sql := REPLACE(v_sql, ':P755_INC_BARG_UNIT',:P755_INC_BARG_UNIT);
RETURN v_sql;
END; But before doing it read this:
http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:210612357425
After reading you will be able to find the best solution yourself.
Lev -
Exception in connection with MS sql-server2000
i have following code
import java.sql.*;
import java.*;
class Conn2
public static void main(String args[])throws Exception
Driver d=(Driver)Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
Connection con=null;
try
con = DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;databaseName=pubs","sa", "");
catch(SQLException e)
e.printStackTrace();
System.out.println(e.getMessage());
if(con!=null)
System.out.println("connection done");
I have installed driver for sql server2000 from http://www.microsoft.com/downloads/details.aspx?FamilyID=4f8f2f01-1ed7-4c4d-8f7b-3d47969e66ae&displaylang=en
Exception is
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establis
hing socket.
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSConnection.<init>(Unknown Source)
at com.microsoft.jdbc.sqlserver.SQLServerImplConnection.open(Unknown Sou
rce)
at com.microsoft.jdbc.base.BaseConnection.getNewImplConnection(Unknown S
ource)
at com.microsoft.jdbc.base.BaseConnection.open(Unknown Source)
at com.microsoft.jdbc.base.BaseDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at Conn2.main(Conn2.java:14)
[Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.
wht should i do??http://forum.java.sun.com/thread.jspa?threadID=419214
Maybe you are looking for
-
This month I downloaded the newest version of PAGES. The documents I have typed using this App will now not open and the message says-"You need a newer version of PAGES to open this document. Could anyone help me with this please. Thanks.
-
How to create a table control from a program internal table
Hi all, I try to create a table control that matches following requirements : - the source table is an internal table from program (not a dictionary table) - I need to specify my own column header titles - the fields need to be editable - some of the
-
Report to display Operating system, and AD boundary or collection ID
I found a report on this site that got me close but it doesn't list the actual operating system and version. I know it should be fairly easy to add but I know next to nothing about SQL. Basically I am just looking for a report to run that will prov
-
Submit button disabed, when uploading eGate.sar
Hi, I am facing a problem when installing Jcaps 5.1 on Solaris 10 sparc. Following are the steps. 1) Successfully installed Repository 2) Successfully logged into web-admin page.(with username and password) 3) From the "browse" button able to add /ca
-
Firefox still won't close properly
I know early this summer an upgrade had a lot of people finding Firefox not closing completely, me included. Since then, a partial bug fix seems to have eliminated it from telling me it can't start because it wasn't closed. However, I still a good ha