Sql query required to fetch data in desired format.
Hi All,
Greetings,
I have 1 table called sessioninfo. below are the table structure and table data,
CREATE TABLE HR.SESSIONINFO
REPORT_DATE DATE,
REPORT_TIME VARCHAR2(100 BYTE),
SESSION1 NUMBER,
SESSION2 NUMBER,
SESSION3 NUMBER,
SESSION4 NUMBER,
SESSION5 NUMBER,
SESSION6 NUMBER,
SESSION7 NUMBER,
SESSION8 NUMBER,
SESSION9 NUMBER,
SESSION10 NUMBER,
SESSION11 NUMBER,
SESSION12 NUMBER,
SESSION13 NUMBER,
SESSION14 NUMBER,
SESSION15 NUMBER,
SESSION16 NUMBER,
SESSION17 NUMBER,
SESSION18 NUMBER,
SESSION19 NUMBER,
SESSION20 NUMBER,
SESSION21 NUMBER,
SESSION22 NUMBER,
SESSION23 NUMBER,
SESSION24 NUMBER,
SESSION25 NUMBER,
SESSION26 NUMBER,
SESSION27 NUMBER,
SESSION28 NUMBER,
SESSION29 NUMBER,
SESSION30 NUMBER,
SESSION31 NUMBER,
SESSION32 NUMBER,
SESSION33 NUMBER,
SESSION34 NUMBER,
SESSION35 NUMBER,
SESSION36 NUMBER,
SESSION37 NUMBER,
SESSION38 NUMBER,
SESSION39 NUMBER,
SESSION40 NUMBER,
SESSION41 NUMBER,
SESSION42 NUMBER,
SESSION43 NUMBER
REPORT_DATE REPORT_TIME SESSION1 SESSION2 SESSION4 SESSION5 SESSION6 SESSION7 SESSION8 SESSION9 SESSION10 SESSION11 SESSION14 SESSION15 SESSION16 SESSION17 SESSION18 SESSION19 SESSION20 SESSION21 SESSION22 SESSION23 SESSION24 SESSION25 SESSION26 SESSION27 SESSION30 SESSION31 SESSION32 SESSION35 SESSION36 SESSION37 SESSION38 SESSION40 SESSION41 SESSION42 SESSION43
8/22/2011 7:01:00 2 1 2 2 1 2 1 2 1 1 1 1 1 2 1 1 0 1 2 2 0 1 1 2 2 2 2 1 1 2
8/22/2011 7:15:41 1 2 2 2 2 3 1 2 2 1 1 1 1 2 3 1 3 2 2 5 1 1 2 1 2 1 2 1 1 1
8/22/2011 7:30:45 1 1 4 3 2 3 2 2 3 2 1 2 2 1 2 1 2 2 2 2 2 3 2 1 2 2 2 2 1 2
8/22/2011 7:46:10 1 2 1 2 2 2 3 3 3 1 1 3 4 3 1 5 3 3 2 2 3 3 2 3 3 2 3 2 2 2
8/22/2011 8:01:05 5 5 7 4 2 3 3 5 2 6 2 3 2 3 4 4 3 3 4 4 2 4 3 4 2 3 4 3 3 4
8/22/2011 8:15:48 2 4 4 4 5 3 3 3 3 4 3 4 4 4 3 3 5 4 4 4 7 3 3 4 3 3 3 5 4 5
8/22/2011 8:30:50 4 5 3 5 4 3 5 5 5 4 5 5 6 5 4 6 7 3 3 5 7 5 4 4 4 4 5 8 3 4
8/22/2011 8:45:42 4 7 5 5 6 5 4 5 4 4 6 4 6 4 7 5 4 4 7 5 7 5 5 5 6 3 7 6 5 5
8/22/2011 9:01:24 5 6 6 5 3 6 8 6 7 6 4 5 4 7 7 5 6 4 7 5 4 5 4 4 5 6 11 4 6
8/22/2011 9:15:56 5 6 4 4 4 6 6 4 13 5 8 5 4 6 3 5 4 6 8 5 5 6 7 5 5 7 5 7 6 8
8/22/2011 9:30:45 7 7 5 5 12 7 4 5 5 6 15 8 6 7 9 9 5 6 5 5 6 5 5 8 9 9 7 5 7 8
8/22/2011 9:45:41 5 10 7 8 7 6 7 5 6 8 8 7 7 9 5 6 7 9 7 8 6 11 6 10 8 10 6 12 9 12
8/22/2011 10:01:00 8 5 5 9 6 7 6 7 5 7 7 7 9 6 6 7 7 7 11 8 7 8 10 8 6 5 7 6 9 6
8/22/2011 10:16:16 6 8 6 14 9 7 7 10 8 8 23 11 16 6 6 4 8 10 9 7 7 10 7 14 12 7 5 10 11 6
8/22/2011 10:31:09 7 9 8 9 8 7 8 8 9 7 20 11 6 8 9 9 11 8 14 11 12 7 8 7 12 10 12 8 7 11
8/22/2011 10:46:11 7 8 10 8 12 7 7 9 8 9 8 11 10 12 9 8 9 7 8 6 8 9 10 10 9 8 9 18 7 9
8/22/2011 11:01:10 8 7 6 9 13 8 10 9 11 9 10 8 7 8 11 14 6 9 12 8 8 7 17 13 12 7 16 19 14 9
8/22/2011 11:15:40 11 12 9 10 10 11 8 10 9 10 10 8 7 9 8 10 6 10 11 10 8 13 14 8 10 13 9 10 12 10
8/22/2011 11:31:45 8 7 10 11 10 12 11 11 8 13 30 11 8 8 8 7 8 12 7 10 9 10 12 15 11 11 10 9 9 11
8/22/2011 11:46:05 9 7 8 7 12 6 11 8 6 9 8 10 7 8 14 9 8 13 8 23 13 7 12 8 12 8 12 10 9 9
8/22/2011 12:01:22 9 10 10 11 11 10 13 7 9 13 11 11 10 10 8 10 13 12 12 11 10 8 7 8 10 9 20 23 10 9
8/22/2011 12:16:02 8 9 11 10 9 11 12 9 22 9 7 7 6 9 10 11 9 8 9 8 25 6 9 10 12 18 16 10 7 7
8/22/2011 12:31:11 18 11 8 14 9 11 5 8 9 7 8 7 8 7 21 10 13 7 6 10 8 7 10 8 7 10 7 10 10 10
8/22/2011 12:46:15 10 7 11 12 8 13 16 14 23 10 8 10 11 33 9 15 13 16 14 9 10 25 11 7 11 11 9 9 11 8
8/22/2011 13:00:57 13 16 8 10 16 12 6 9 10 7 22 11 11 8 7 15 8 11 10 14 8 15 9 10 10 10 10 8 8 9
8/22/2011 13:15:57 6 21 14 26 7 10 9 13 10 12 13 7 8 18 11 10 10 9 25 17 8 21 7 11 7 18 17 9 17 6
8/22/2011 13:30:53 9 12 6 5 9 14 6 9 7 15 10 6 8 12 8 9 7 9 10 12 7 8 13 11 13 7 8 10 7 10
8/22/2011 13:46:05 6 13 8 9 10 10 8 22 8 11 8 10 10 11 8 10 6 9 9 8 8 7 11 7 9 8 8 7 10 8
8/22/2011 14:00:46 13 8 8 11 9 12 8 9 14 9 9 11 14 10 9 11 14 8 16 23 9 6 12 8 8 9 9 9 18
8/22/2011 14:15:46 8 13 9 7 9 29 7 9 18 10 10 7 9 9 17 10 10 10 12 10 13 12 15 7 12 8 13 9 8 9
8/22/2011 14:31:13 9 11 11 20 10 9 8 9 9 9 8 25 9 7 11 8 9 10 12 7 10 23 11 9 10 9 10 9 9 9
8/22/2011 14:45:52 9 12 12 13 25 11 17 8 12 9 11 10 11 10 11 8 21 11 8 7 9 25 11 10 11 10 13 11 8 8
8/22/2011 15:00:52 7 33 11 9 7 12 9 11 12 10 34 10 11 9 7 9 11 10 9 29 11 10 13 8 10 13 17 15 14 12
8/22/2011 15:16:16 8 10 6 25 13 10 9 9 13 13 15 10 10 17 8 12 10 11 61 9 9 9 26 10 10 12 10 11 13 9
8/22/2011 15:31:07 9 10 9 11 11 9 14 14 12 12 19 12 8 11 11 9 9 12 0 11 10 7 24 11 11 9 19 22 10 9
8/22/2011 15:45:44 7 10 9 25 14 11 23 10 34 11 7 8 7 7 15 16 8 5 9 9 10 10 7 9 7 7 10 10 21 13
8/22/2011 16:00:59 27 9 12 10 11 9 16 16 16 19 10 10 11 9 7 17 10 10 6 27 11 12 9 20 9 10 18 12 12 9
8/22/2011 16:15:42 12 9 8 8 9 18 10 9 25 11 8 8 16 10 13 11 23 33 12 8 11 20 9 8 9 22 10 8 11 10
8/22/2011 16:31:03 10 10 9 14 9 14 10 15 9 14 9 10 11 22 8 9 10 13 8 10 10 8 11 13 10 9 11 10 11 9
8/22/2011 16:45:44 10 9 10 11 13 10 10 12 8 9 10 9 16 7 8 9 8 14 7 10 11 5 7 11 8 9 10 11 20 11
8/22/2011 17:00:46 9 12 10 9 11 7 12 10 9 7 11 8 9 7 8 12 10 10 8 15 12 12 8 6 6 10 9 10 9 9
8/22/2011 17:16:04 7 7 7 20 9 9 9 8 9 8 10 20 8 17 31 10 10 9 8 17 9 8 8 16 8 6 14 10 9 9
8/22/2011 17:31:22 6 7 9 9 8 6 8 7 8 9 5 18 8 7 8 7 7 12 13 11 16 8 7 25 9 8 22 12 14 10
8/22/2011 17:45:56 12 6 11 8 8 8 7 6 7 7 7 15 9 8 10 10 13 14 5 9 9 19 9 6 5 14 17 9 14 6
8/22/2011 18:00:53 8 8 6 8 7 8 5 8 6 7 6 8 16 5 7 7 9 15 8 8 6 8 6 8 9 7 10 7 6 10
8/22/2011 18:16:04 6 7 6 19 12 12 9 9 8 6 6 7 12 8 7 7 5 6 7 7 7 10 6 7 8 6 6 6 6 9
8/22/2011 18:31:00 7 6 9 6 11 6 6 6 6 9 6 5 7 7 12 9 18 8 5 5 5 7 5 6 10 6 10 10 15 8
8/22/2011 18:45:43 17 13 22 11 5 6 6 6 12 4 5 5 5 4 5 5 9 8 4 6 7 5 6 6 7 5 6 7 6 5
8/22/2011 19:00:57 7 7 4 7 15 17 6 7 10 8 4 6 6 4 5 6 5 13 7 5 6 3 5 5 6 6 16 7 6 4
8/22/2011 19:15:47 5 4 6 5 4 4 4 4 6 3 5 5 6 4 3 10 6 6 4 7 5 6 6 6 7 5 4 4 8 5
8/22/2011 19:30:39 5 5 7 4 8 12 3 5 3 5 6 6 4 5 4 4 5 6 4 6 5 4 4 6 7 4 4 6 4 3
8/22/2011 19:45:39 5 5 15 5 6 6 6 4 5 8 6 6 6 4 6 5 7 4 3 5 3 3 3 4 6 7 6 4 5 5
8/22/2011 20:01:02 3 4 4 5 3 6 4 5 5 4 2 3 4 4 5 6 4 4 5 4 5 5 4 5 3 5 5 3 4 5
8/22/2011 20:15:38 6 4 3 4 5 5 4 2 5 3 4 6 4 4 4 5 2 2 4 4 5 4 3 2 4 3 5 4 3 4in short table contains the information about some sessions.
now i want the output like below, (highest session for the report_date and report_time with the name of session)
REPORT_DATE REPORT_Hour SESSION_CODE SESSION_VALUE
8/22/2011 7 Session30 5
8/22/2011 7 Session24 5
8/22/2011 8 Session41 8
8/22/2011 9 Session19 15
8/22/2011 10
8/22/2011 11
8/22/2011 12
8/22/2011 13
8/22/2011 14
8/22/2011 15
8/22/2011 16
8/22/2011 17
8/22/2011 18
8/22/2011 19
8/22/2011 20 How can i get using sql query.
Any help appriciated.
In version 11 you can use UNPIVOT.
A sample with just three columns:
SQL> with sessioninfo as (
2 select date '2011-08-29' report_date, '7:12:34' report_time,
3 1 session1, cast(null as number) session2, 11 session3 from dual union all
4 select date '2011-08-29' report_date, '7:56:00' report_time,
5 4 session1, 2 session2, cast(null as number) session3 from dual union all
6 select date '2011-08-29' report_date, '14:44:44' report_time,
7 cast(null as number) session1, cast(null as number) session2, 2 session3 from dual
8 )
9 select
10 report_date,
11 substr(lpad(report_time,8),1,2) report_hour,
12 max(session_code) keep (dense_rank last order by session_value) session_code,
13 max(session_value) session_value
14 from sessioninfo
15 unpivot(
16 session_value for session_code in (
17 session1 as 'Session1',
18 session2 as 'Session2',
19 session3 as 'Session3'
20 )
21 )
22 group by
23 report_date,
24 substr(lpad(report_time,8),1,2)
25 order by
26 report_date,
27 substr(lpad(report_time,8),1,2)
28 ;
REPORT_D RE SESSION_ SESSION_VALUE
11-08-29 7 Session3 11
11-08-29 14 Session3 2For your 43 columns you just need to expand the list in lines 17,18,19 - the rest will work fine.
(Your best way would actually be to change your datamodel to be more useful in a relational database - having columns session1, session2,...,session43 is not a very useful datamodel. Storing a timestamp in a VARCHAR2 is also not very good for the database.)
Similar Messages
-
Failed to parse SQL query: ORA-01403: no data found
I'm going to post and answer my own question in the hope that others will not have to struggle with this error.
Using a report of the type PL/SQL Function Body Returning SQL and using generic columns you may run into this error
failed to parse SQL query:
ORA-01403: no data found
The SQL will run stand alone but the report fails.
There is a setting just below the source you should check:
"Maximum number of generic report columns"
In my case the number of columns was dynamic and when it exceeded the number set as the maximium number of generic columns I received the 1403 error.
Hope this helps someone.
GregThanks for much for the pointer. For anyone else struggling with this too, I found that my generic columns had unordered themselves. Reordering them solved the problem for me.
Edited by: user11096971 on Jul 22, 2010 3:19 AM -
Adhoc Query Requirement with Multiple Data Source
Hi All,
I have a Adhoc Query Requirement with Multiple Data Source. Is there any way to achive it. Other than Resultant set and bring into Model.
Thanks
SSYou can compare stuff in the EL, but I don't think this is what you need.
You can just use Java code in the backing bean class for all the business logic. You can use DAO classes for database access logic. Finally for displaying you can use the JSF tags such as h:outputText. -
hi
i need to a query to get the data as per given structure below.
tha data should be based on stock code and dates.
for example : stock_code = 01 and
from date 01/01/08
to date 31/01/08
Date particulars reciepts issued returns closing bal
01/01/08 opening balance 0
01/01/08 recieved stock : no 1 18 18
02/01/08 issued stock : no 5 5 13
03/01/08 return stock : no 50 3 16
and so on
here is the tables i m using
SQL> desc bal_sheet (balance sheet holds the opening and closing record)
Name Null? Type
BDATE DATE
ACC_CODE VARCHAR2(20)
OPENBAL NUMBER(20,4)
CLOSEBAL NUMBER(20,4)
SQL> desc stock_reg
Name Null? Type
STOCKCODE NOT NULL VARCHAR2(20)
ITEM_CODE VARCHAR2(10)
DESCR NOT NULL VARCHAR2(50)
COMCODE VARCHAR2(6)
COMPANY NOT NULL VARCHAR2(200)
SHORT_NAME VARCHAR2(10)
PACK VARCHAR2(10)
PRICE NUMBER(10,4)
TOTAL_STOCK NUMBER
SQL> DESC PURCHASE_HEADER
Name Null? Type
P_ID NOT NULL VARCHAR2(10)
ACC_CODE VARCHAR2(10)
P_DATE DATE
REMARK VARCHAR2(500)
INVOICE_DATE DATE
NTOTAL NUMBER(12,4)
SQL> DESC PURCHASE_DETAIL
Name Null? Type
STOCKCODE VARCHAR2(20)
P_ID VARCHAR2(10)
QTY NUMBER
BONUS NUMBER
PRICE NUMBER(15,4)
EXPIRE_DATE DATE
DAMAGE NUMBER
AMOUNT NUMBER(15,4)
SQL> DESC SALES_HEADER
Name Null? Type
S_ID NOT NULL VARCHAR2(8)
ACC_CODE VARCHAR2(10)
SALES_MANID VARCHAR2(20)
S_DATE DATE
REMARKS VARCHAR2(500)
NTOTAL NUMBER(12,4)
SQL> DESC SALES_DETAIL
Name Null? Type
S_ID NOT NULL VARCHAR2(8)
STOCKCODE NOT NULL VARCHAR2(20)
QTY NUMBER
BONUS NUMBER
BATCH_NO NOT NULL VARCHAR2(10)
EXPIRY_DATE DATE
AMOUNT NUMBER(15,4)
SQL> DESC SALES_HEADER
Name Null? Type
SR_ID NOT NULL VARCHAR2(8)
ACC_CODE VARCHAR2(10)
SALES_MANID VARCHAR2(20)
S_DATE DATE
REMARKS VARCHAR2(500)
NTOTAL NUMBER(12,4)
SQL> DESC SALES_DETAILR
Name Null? Type
SR_ID NOT NULL VARCHAR2(8)
STOCKCODE NOT NULL VARCHAR2(20)
QTY NUMBER
BONUS NUMBER
BATCH_NO NOT NULL VARCHAR2(10)
EXPIRY_DATE DATE
AMOUNT NUMBER(15,4)
hope the information would be enough to get understand the problemQuery required to get data Agreed ! Even on your side it is required.
Well, please, understand we are not here to do your job. So, make effort on your side, show us what you have already done/tried, and post here your results.
And also, use the tags [pre] and [/pre] around your code against the forum side to keep your post readable.
Help us to help you,
Nicolas. -
The best SQL query tool to visualize data relationship
Bay Breeze Software just released SQL Edge 1.4, please refer to http://www.baybreezesoft.com for product details.
SQL Edge is an Eclipse Rich Client application that allows users to execute SQL queries, browse schema information in ER diagrams, and visualize data relationships. With SQL Edge, users can use only one query to retrieve data in a master table, and then browse data in all related detail tables. Users can also insert, edit, and delete table records in the data grids.
SQL Edge has five perspectives. The "Query Perspective" allows users run any SQL queries, while the "Schema Perspective" displays table schema information.
There are two relationship perspectives. The "Relationship Table View" displays data in the master-detail style. The "Relationship Tree View" displays master table records as top-level tree nodes. The nodes can be expanded to reveal any level of related detail records. In addition, clicking any node will display the corresponding data in a detail grid.
The "Model Perspective" displays tables and their relationships in ER diagrams. The tables can be from different databases. Users can define master-detail relationships among these tables, and print or save the diagram for future reference.
The version 1.4 added following features:
(1) Added support for synonyms and CLOB data type.
(2) Added load on demand feature to support large result sets. In query perspective and relationship table view, a selection query will only fetch enough rows to populate the data grids. Users can scroll down the grids to fetch more rows if needed.
The version 1.3 added following features:
(1) Added model perspective to display tables and their relationships in ER diagrams. The tables can be from different databases. Users can define master-detail relationships among these tables, and print or save the diagram for future reference.
The version 1.2 features are:
(1) Support any JDBC compatible databases.
(2) Allow users to specify JDBC drivers at run-time, and provide wizards to help setup JDBC connections. Easy to install, and easy to setup.
(3) SQL editor with syntax highlighting based on currently connected databases.
(4) SQL edtior allows users to execute SQL queries asynchronously. Users can cancel the execution by click the "Cancel" button or just close the SQL Editor.
(5) Schema perspective displays the table schema information, including column definitions, primary key, indexes, and foreign keys.
(6) Relationship table view displays the related data in the master-detail style, with master table data shown in the top grid, and all related detail table data in a list of bottom grids.
(7) Relationship tree view displays the master table records as top-level tree nodes, and the related detail records as child nodes. Click any of these tree nodes will display the corresponding record data in a detail grid.
(8) Allow users to insert, edit, and delete records in the master and detail grids of the relationship table view and relationship tree view.
(9) Allow users to define master-detail relationships even between tables in different databases. This enables the relationship table view and relationship tree view to display data relationships between tables in different databases or without pre-defined foreign keys.Good to know. Thank you for the information.
Bye, Aron -
Entity Framework Query - Unable to fetch data
I am working on a WPF application and using Entity framework 6.0
I have written following query to fetch data from database but could not fetch any data:
var customersList = context.Customers.Include(x => x.ReturnedCustomerItems.Select(y => y.ReturnedLotItem)).Where(x => x.IsDeleted != false).ToList();
Notes:
1. context: Database Context Object
2. Customers: DbSet for Customer's table
3. ReturnedCustomerItems: List of Customer Items to be returned.
4. ReturnedLotItem: Lot Item corresponding to Returned Customer Item. Each Customer Item will have a corresponding lot item..
Following is the SQL Query I have written to check whether data exits inside database:
select * from
transportapp.dbo.customer cust,
transportapp.dbo.ReturnedCustomerItem ret,
transportapp.dbo.ReturnedLotItem item
where
cust.CustomerId = ret.CustomerId
and ret.BookingItemId = item.BookingItemId
As output I got the following data records:
Following is the Table structure generated by Entity Framework:
CREATE TABLE [dbo].[ReturnedCustomerItem] (
[BookingItemId] INT NOT NULL,
[IsDeleted] BIT NOT NULL,
[CustomerId] INT NOT NULL,
[ReturnCharge] DECIMAL (18, 2) NOT NULL,
[DemurrageCharge] DECIMAL (18, 2) NOT NULL,
[Weight] DECIMAL (18, 2) NOT NULL,
[Quantity] INT NOT NULL,
[ReturnDate] DATETIME NOT NULL,
[Status] NVARCHAR (100) NULL,
CONSTRAINT [PK_dbo.ReturnedCustomerItem] PRIMARY KEY CLUSTERED ([BookingItemId] ASC),
CONSTRAINT [FK_dbo.ReturnedCustomerItem_dbo.Customer_CustomerId] FOREIGN KEY ([CustomerId]) REFERENCES [dbo].[Customer] ([CustomerId]) ON DELETE CASCADE,
CONSTRAINT [FK_dbo.ReturnedCustomerItem_dbo.ReturnedLotItem_BookingItemId] FOREIGN KEY ([BookingItemId]) REFERENCES [dbo].[ReturnedLotItem] ([BookingItemId])
CREATE TABLE [dbo].[ReturnedLotItem] (
[BookingItemId] INT NOT NULL,
[IsDeleted] BIT NOT NULL,
[IsReturned] BIT NOT NULL,
[ReturnCharge] DECIMAL (18, 2) NOT NULL,
[DemurrageCharge] DECIMAL (18, 2) NOT NULL,
[Weight] DECIMAL (18, 2) NOT NULL,
[Quantity] INT NOT NULL,
[LotId] INT NOT NULL,
[LotItemId] INT NOT NULL,
CONSTRAINT [PK_dbo.ReturnedLotItem] PRIMARY KEY CLUSTERED ([BookingItemId] ASC),
CONSTRAINT [FK_dbo.ReturnedLotItem_dbo.BookingItem_BookingItemId] FOREIGN KEY ([BookingItemId]) REFERENCES [dbo].[BookingItem] ([BookingItemId]),
CONSTRAINT [FK_dbo.ReturnedLotItem_dbo.ReturnedLot_LotId] FOREIGN KEY ([LotId]) REFERENCES [dbo].[ReturnedLot] ([LotId]) ON DELETE CASCADE,
CONSTRAINT [FK_dbo.ReturnedLotItem_dbo.LotItem_LotItemId] FOREIGN KEY ([LotItemId]) REFERENCES [dbo].[LotItem] ([BookingItemId]) ON DELETE CASCADE
I am unable to debug the LINQ expression where I am going wrong. Need help in identifying the mistake.
Thanks!!
NBThe best way of debugging the SQL is to change the where portion
1) First eliminate the 'where'
2) Run with only one where statement : cust.CustomerId
= ret.CustomerId
3) Run with the other where : ret.BookingItemId
= item.BookingItemId
Then compare the 3 results. Your database may not contain any data that has both where statements true.
jdweng -
SQL query result with HTML Data in output
Hello,
I have a SQL table , in one column I store HTML data. I need to query the table and get the HTML data in the columns that have 'HREF'. The output shows as grid on the sql management studio, however when I export it to excel, the HTML data does not get copied
correctly, since there are HTML tags etc.
How can I export the report correctly from SQL ?Hello,
The HTML data is stored in a column with datatype as nvarchar(max). Sample data in the column is shown below. It is with formatting etc and is rendered as is on the web page. the business wants to generate a quick report so that they can see the pages that
have links displayed. I can do that by querying the columns that have a 'HREF' in the text.
Can I get the exact HREF values using just sql query? There can be more than one links on a page.
Also, If I just want to copy the whole column and paste it on excel, how can I do that? If I copy the data below and paste, it does not get copied in one cell.. it spreads across multiple cells, so the report does not make any sense.
<br />
<table border="0" cellpadding="0" cellspacing="0" style="width: 431pt; border-collapse: collapse;" width="574">
<tbody>
<tr height="19" style="height: 14.25pt; ">
<td height="19" style="border: 0px blue; width: 431pt; height: 14.25pt; background-color: transparent;" width="574"><a href="https:"><u><font color="#0066cc" face="Calibri">ax </font></u></a></td>
</tr>
</tbody>
<colgroup>
<col style="width: 431pt; " width="574" />
</colgroup>
</table> -
Sql query to get Thursday (Date) for the year 2014
Hello All,
I want to get the date for all the Thursdays in the year 2014. How can I achieve this using SQL query? Can anybody give me a hand with this? Thanks.
AmolHi,
Check if this can help you
DECLARE @counter INT
DECLARE @Date Date
SELECT @counter = 0
Select @Date = '20131226'
WHILE @counter <= 52
BEGIN
select Thursday = convert(varchar(10),DATEADD(WEEK,1, @Date),120)
SELECT @counter = @counter + 1
Select @Date = DATEADD(WEEK,1, @Date)
END
Regards
Prasad Tandel
Please dont forget to mark as answer if this helps you :) -
Sql query generator from xml data
Hi,
I am looking for an open source tool in java which would generate the sql query with an xml configuration file as input. The xml configuration file schema would be defined by the tool and and would provide placeholders for giving the various information required to build the sql query.
Are there any available?
Please let me know.
Anshukhi All,
I tried below . but still no luck .
CREATE OR REPLACE FUNCTION get_audit_trail_log(cikey IN INTEGER) RETURN blob IS
CURSOR c_log(l_cikey INTEGER) IS
SELECT *
FROM PROD_SOAINFRA.audit_details atr
WHERE cikey = l_cikey
ORDER BY count_id;
bl BLOB;
BEGIN
dbms_lob.createtemporary (bl, TRUE);
FOR r_log IN c_log(cikey)
LOOP
dbms_lob.append (bl,r_log.log);
END LOOP;
RETURN(bl);
END;
=======================================
SELECT UTL_RAW.CAST_TO_VARCHAR2(UTL_COMPRESS.LZ_UNCOMPRESS(get_audit_trail_log(ci.cikey)))
FROM PROD_SOAINFRA.audit_details ci
WHERE cikey = 848063749
=======================================
Error:
=====================
ORA-22835: Buffer too small for CLOB to CHAR or BLOB to RAW conversion (actual: 20958, maximum: 2000)
22835. 00000 - "Buffer too small for CLOB to CHAR or BLOB to RAW conversion (actual: %s, maximum: %s)"
*Cause: An attempt was made to convert CLOB to CHAR or BLOB to RAW, where
the LOB size was bigger than the buffer limit for CHAR and RAW
types.
Note that widths are reported in characters if character length
semantics are in effect for the column, otherwise widths are
reported in bytes.
*Action: Do one of the following
1. Make the LOB smaller before performing the conversion,
for example, by using SUBSTR on CLOB
2. Use DBMS_LOB.SUBSTR to convert CLOB to CHAR or BLOB to RAW. -
SQL Query for SSRS has data but fields don't show that data
I am having a strange issue here with my new report;
First off, this report is an availability report for employees. If they are busy then a 0 should be displayed for that Hour and if they are free then a 1 is to be displayed. There are 2 parameters setup for use in this query, one is a Date/Time parameter
and the other is a Text parameter where another Dataset Query is grabbing the data for (Departments)
I have 2 Parameters, 1 is for a Department and the other is to select the date.
Hour1 Hour2 Hour3 Hour4 Hour5
Hour6 Hour7
Smith, John | 1 | 0 | 0 | 0 |
1 | 1 | 1 |
Som, One | 1 | 1 | 1 | 0
| 0 | 1 | 1 |
When I run the query in the Query Designer for the Dataset the information is displayed correctly and as I would expect it, however, when I run the Report and choose the same information for the 2 parameters then the report only ever shows all 1's;
Smith, John | 1 | 1 | 1 | 1 |
1 | 1 | 1 |
Som, One | 1 | 1 | 1 | 1
| 1 | 1 | 1 |
I've tried searching but didn't know what term to use that describes what is going on.
Like I said, this works if ran in SSMS and works when ran in the Query Builder of SSRS but when it comes to displaying the data on the report the incorrect information is displayed.
Any help would be appreciated.
EDIT
I have also ran the Report Table Wizard with the same query and chosen Names as the row and Hours as the columns and the same thing happens - just all 1's are displayed even thought the query in Query Builder shows correct information.The difference running the query directly in query designer and when the report runs is that you manually type in values for the parameters when running query designer. It is likely that the parameter values from the report have a different syntax than you
expect. This will happen especially when setting the available values of a parameter from a data cube query. A value from an analysis cube may be displayed in the query designer as "\Project\Iteration Node" while the actual value is "[Work Item].[Iteration
Hierarchy].[Iteration2].&[-7189901615194941888]&[-8272609059741292246]". Very different as you can see. This example is from the TFS analysis server.
The best way to validate that your parameters are passing the values (and syntax) you expect is to add text boxes to your report for each parameter and set them to display Parameters!ParameterName.Value.
"You will find a fortune, though it will not be the one you seek." -
Blind Seer, O Brother Where Art Thou
Please Mark posts as answers or helpful so that others may find the fortune they seek. -
SQL Query fails with Fetch error
We are running JDE ERP 9.0 and have a report that gets this error
“JDB3300020 - Fetch not allowed. Prior successful Select operation required for this request.”
I’ve been troubleshooting this problem for months, and I am no closer to the root cause and need some help. I’ve engaged Microsoft support, we collected a trace but could not find anything that pointed to the cause.
Execution details:
Report runs successfully after database server is rebooted. Otherwise we have to keep rerunning as many as 15 times to get a successful run. When we discovered that report would run after the server reboot, we decided
to only restart SQL, to see if it was Query plan related but it still failed. How can we determine why the reboot is making a difference?
Any ideas/help is welcome.Using Profiler to capture what JD Edwards sends to SQL Server seems like a good idea. And include the events Error:Exception and Error:UserMessage to see if that captures anything.
I googled on the message, and I found
http://www.jdelist.com/ubb/showflat.php?Cat=&Number=111077&page=0&view=collapsed&sb=5&o=
where the cause was that different indexes were used for SELECT and FETCH. (Whatever that means; I was not able to grasp it.)
Erland Sommarskog, SQL Server MVP, [email protected] -
SQL query and Delete the data based on condition
Hi All,
I have one requirement like I need to fetch the data from the table, In that table one filed (XXXXX) domain type is STAMP.
delete the data if the sy-datum ( length 8) is greater than field XXXXX which has length 14.
Please suggest me how to delete or fetch the data with the same length.
I have used below code..but did not work..
"Concatenate sy-datum '%' into gv_var1.
select *
from DD03l
into itab
where XXXX like gv_var1."
and tried this one as well
1. DELETE itab WHERE XXXXX GT sy-datum.
2. DELETE itab WHERE XXXXX GT gv_var1.Hi,
When dates are in different formats you have to always convert them into one common format and then do the checks. Its better to convert the date in the variable into timestamp(using CONVERT DATE statement-look for abapdocu for its usage) and then compare it with the date on database.
data: gv_var1 TYPE timestamp.
convert date sy-datum into time stamp gv_var1.
select *
from DD03l
into itab
where XXXX like gv_var1.
should work now.
Hope this helps.
Shwetha -
Simple SQL Query required....
Hi All,
I have 2 tables like the below.
Table "T1". This has c1,c2,c3 columns
Table "T2". This has c1,c2,c3 columns as T1 with same datatypes.
now i want a query which fetch the data like t1.c1,t1.c2,t1.c3,t2.c1,t2.c2,t2.c3
Eg:
T1 has the below data:
c1 c2 c3
1 200 300
2 200 300
1 100 300
2 400 400
T2 has the below data:
c1 c2 c3
1 200 300
2 200 300
2 400 400
now i want the output like the below
c1 c2 c3 c1 c2 c3
1 200 300 1 200 300
2 200 300 2 200 300
1 100 300
2 400 400 2 400 400
Regards
Bond..Hi
you can use this
Select t1.c1,t1.c2,t1.c3,t2.c1,t2.c2,t2.c3
from table1 t1,table2 t2
where t1.c1 = t2.c1(+)
AND t1.c2 = t2.c2(+)
AND t1.c3 = t2.c3(+)
order by t1.c1,t2.c1
Regards
Ankur
Edited by: Garg on Dec 4, 2008 2:16 PM
Edited by: Garg on Dec 4, 2008 2:20 PM -
SCCM 2007 SQL Query for Advertisement Creation Date
I have been asked if I can create a Query to list all advertisements that have been created in a 60 day period and the User that created them.
I have tried a couple of SQL codes but I cant quite get the syntax to work.
Here is what I have so far, but I still don't know if any of it is usable:
v_Advertisement.AdvertisementName AS ‘Advertisement Name’,
v_Advertisement.AdvertisementID AS ‘Advertisement ID’
FROM v_Advertisement
INNER JOIN v_Package ON v_Advertisement.PackageID = v_Package.PackageID
INNER JOIN v_Collection ON v_Advertisement.CollectionID = v_Collection.CollectionID
INNER JOIN v_ClientAdvertisementStatus ON v_Advertisement.AdvertisementID = v_ClientAdvertisementStatus.AdvertisementID
AND v_Advertisement.AdvertisementID in(SELECT advertisementid FROM V_advertisement WHERE DATEDIFF(D, V_advertisement.presenttime,GETDATE())<=365)
ORDER BY v_Advertisement.AdvertisementName
Any help with this would be greatly appreciated.
Regards
AntonSKI saw you're missing select statement.
Also, you need to know which table & column for these:
- Advertisement Creation date?
- User that created the Advertisement
a sample of working query as below, but it's still missing the 2 items above
select
Adv.AdvertisementName as 'Advertisement Name',
Adv.AdvertisementID as 'Advertisement ID'
from
v_Advertisement as Adv
inner join v_Package as Pkg on Adv.PackageID = Pkg.PackageID
inner join v_Collection as Col on Adv.CollectionID = Col.CollectionID
inner join v_ClientAdvertisementStatus as AdsStatus on Adv.AdvertisementID = AdsStatus.AdvertisementID
and Adv.AdvertisementID in(select Adv.AdvertisementID from v_Advertisement where datediff(d, Adv.PresentTime, getdate())<=365)
order by 'Advertisement Name'
---Pat -
SQL Loader Approch to fetch data from Previous Data Segment.
CREATE TABLE T
RECORD_ID NUMBER,
SEG_VALUES VARCHAR2(4000)
==============================================================================
LOAD DATA
INFILE *
TRUNCATE
INTO TABLE T
WHEN SEG_VALUES <> ''
RECORD_ID RECNUM,
SEG_VALUES POSITION(1:4000)
BEGIN DATA
AAASH9561000000074120081029SYS
BBB0000001H0351
CCC0000001 6040818 078141532A 202007083020070830 36274
CCC0000002 12623239 526486168A 202008063020080630 4808
CCC0000003 13326331 530229550A 202008042620080426 V4611
CCC0000004 23554261 161340499A 202008082220080822 6868
==============================================================================
CREATE TABLE T1
FILE_ID VARCHAR2(20),
CONT_NBR VARCHAR2(20),
SEG_VALUES VARCHAR2(4000)
==============================================================================
CREATE OR REPLACE PROCEDURE P
AS
l_Fileid T1.file_id%type;
l_Contractnbr t1.CONT_NBR%Type;
BEGIN
FOR REC IN (SELECT SEG_VALUES FROM T ORDER BY RECORD_ID)
LOOP
IF SUBSTR(REC.SEG_VALUES,1,3) ='AAA' THEN
l_Fileid := SUBSTR(REC.SEG_VALUES,10,10);
ELSIF SUBSTR(REC.SEG_VALUES,1,3) ='BBB' THEN
l_Contractnbr := SUBSTR(REC.SEG_VALUES,11,5);
ELSIF SUBSTR(REC.SEG_VALUES,1,3) ='CCC' THEN
INSERT INTO T1 VALUES (l_Fileid,l_Contractnbr,REC.SEG_VALUES);
END IF;
END LOOP;
COMMIT;
EXCEPTION
WHEN OTHERS THEN
RAISE_APPLICATION_ERROR (-20458,SQLERRM);
END P;
==============================================================================
Is there is any simple approch to handle the above scenario in SQL Loader Control file? if possible can you please show me?Handle the above scenario? What above scenario?
Could I guess ... you betcha. Will I guess? Quite another matter.
Please provide full version (all 3 decimal places) and a clear and concise description of what help you need.
Maybe you are looking for
-
ITunes no longer displays CDs after latest install
I've seen similar older questions, but I haven't seen an answer that works yet. I Just installed latest iTunes SW (12.1.x?) on 2/28/15. Now iTunes does not display (or ask to display/import) a CD when I insert one (or have one inserted). (My prefe
-
External hard drive and lightroom
I have a macbook pro with 2 G memory. I am running out of space on my hard drive. I want to put my photos on an external drive. I want to get: a plug-in work horse for full backups another external for just photos. I tend to work around the house wit
-
Photo albums not appearing in site on own server
Hi, I have a small personal site, www.baskie.com it's built (badly!) using iWeb and it's hosted on my own server. When I used iWeb 08, published to a folder, then uploaded to my server using an FTP client as was well, now with iWeb09 I have set thing
-
CAN I INSTALL ONLY WINDOWS XP ON MAC MINI SINGLE BOOT NO OSX
-
Can we install BW3.5 in R3
hi, I am very new to sAP basis CAn we install SAP BW in R/3 enterprise If so please let me know the procedure to install the SAP BW And also let me know the steps to install eCC 6.0