Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Using the LEVEL using WITH

Author  Topic 

kawadeprasad
Starting Member

13 Posts

Posted - 2012-06-07 : 05:45:25
Hi,
I would like to know how Connect By Prior works?

I have below query and it's not getting executed.
Please help.

/* Formatted on 2012/06/05 15:20 (Formatter Plus v4.8.7) */
WITH rec AS
(
SELECT 'Vivek' first_name, 'Johari' last_name, 'Gudgaon' city, 110.15 sales
FROM DUAL
UNION ALL
SELECT 'Sunil' first_name, 'Sharma' last_name, 'Gorakhpur' city, 125.09 sales
FROM DUAL
UNION ALL
SELECT 'Chetan' first_name, 'Mehra' last_name, 'Indore' city, 124.89 sales
FROM DUAL
UNION ALL
SELECT 'Ninad' first_name, 'Chauhan' last_name, '' city, 112.64 sales
FROM DUAL
UNION ALL
SELECT 'Vinit' first_name, 'Gouda' last_name, 'Hubli' city, 110.9 sales
FROM DUAL
UNION ALL
SELECT 'Rizvan' first_name, 'Shekh' last_name, '' city, 129.00 sales
FROM DUAL
UNION ALL
SELECT 'Ram' first_name, 'Joshi' last_name, 'Pune' city, 105 sales
FROM DUAL
UNION ALL
SELECT 'Alex' first_name, 'Parera' last_name, 'Pune' city, 110.70 sales
FROM DUAL
UNION ALL
SELECT 'Rajiv' first_name, 'Naroola' last_name, 'Gudgaon' city, 131.63 sales
FROM DUAL
UNION ALL
SELECT 'Ajay' first_name, 'Gandhi' last_name, 'Jaipur' city, 131.80 sales
FROM DUAL
UNION ALL
SELECT 'Sandeep' first_name, 'Sharma' last_name, 'Jaipur' city, 121.80 sales
FROM DUAL
UNION ALL
SELECT 'Vinod' first_name, 'Singh' last_name, '' city, 141.80 sales
FROM DUAL)

SELECT * --COUNT(*)
FROM rec
START WITH City = 'Pune'
CONNECT BY PRIOR Sales > 110

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-06-07 : 05:51:02
You are not using Microsoft SQL Server right ?

SQLTeam.com is on MS SQL Server. For other databases try dbforums.com


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

kawadeprasad
Starting Member

13 Posts

Posted - 2012-06-07 : 06:01:00
fine thanks. I was using Oracle.
Go to Top of Page
   

- Advertisement -