i have made 2 views and concted them and my query is working find, but i want to make a 1 stored procedure from these 2 views ... View 1 - SELECT dbo.page_information.page_id
-
FROM dbo.user_pages INNER JOIN
-
dbo.page_information ON dbo.user_pages.page_id = dbo.page_information.page_id
-
WHERE (dbo.user_pages.e_id = 32)
View 2 - SELECT dbo.page_information.page_id AS Expr1
-
FROM dbo.VIEW1 RIGHT OUTER JOIN
-
dbo.page_information ON dbo.VIEW1.page_id = dbo.page_information.page_id
-
WHERE (dbo.VIEW1.page_id IS NULL)
Please can u hlp me out
10 5925
i have made 2 views and concted them and my query is working find, but i want to make a 1 stored procedure from these 2 views ... View 1
SELECT dbo.page_information.page_id
FROM dbo.user_pages INNER JOIN
dbo.page_information ON dbo.user_pages.page_id = dbo.page_information.page_id
WHERE (dbo.user_pages.e_id = 32) View 2
SELECT dbo.page_information.page_id AS Expr1
FROM dbo.VIEW1 RIGHT OUTER JOIN
dbo.page_information ON dbo.VIEW1.page_id = dbo.page_information.page_id
WHERE (dbo.VIEW1.page_id IS NULL)
Please can u hlp me out
may i know why you need to create a stored proc from this view? if your stored proc will just contain this view, stored proc might not be your solution...
-- C K
By combining these two views iam getting a result...
I am developing a complete webbased solution in which i am required to have all the sql quries in procedures not in views....
so i simple want to combine into one query and make a stored procedure.
-
SELECT The,Fields,You,Want
-
FROM View1
-
TheJoinType View2 ON TheJoinCriteria
-
Where TheJoinType= LEFT JOIN or JOIN or whatever
Put that into a stored proc, or even another view
Use a stored proc if you want to parameterize the query
otherwise do it as another view
as another alternative you could do this -
SELECT The,Fields,You,Want
-
FROM
-
( SELECT dbo.page_information.page_id
-
FROM dbo.user_pages
-
INNER JOIN dbo.page_information
-
ON dbo.user_pages.page_id =dbo.page_information.page_id
-
WHERE (dbo.user_pages.e_id = 32)
-
) a
-
-
JOIN
-
-
( SELECT dbo.page_information.page_id AS Expr1
-
FROM dbo.VIEW1
-
RIGHT OUTER JOIN dbo.page_information
-
ON dbo.VIEW1.page_id = dbo.page_information.page_id
-
WHERE (dbo.VIEW1.page_id IS NULL)
-
) b
-
ON a.JoinField=b.JoinField
-
That way there is only 1 view or 1 stored proc, whichever you decide to go with.
Of course if the other 2 views are likely to be used in other places then the way you have them now is the way to go
if you're allowed to create function, try creating a function that returns a table...and call it as if it's a table/view
select * from mydb.dbo.myTableFunction() where....
-- ck
I dont want any view....
i only want is to make one query instead of these two's.
and after that i'll make it a stored procedure
I dont want any view....
i only want is to make one query instead of these two's.
and after that i'll make it a stored procedure
created procedure syntax
-- CK
I know how to create a stored procedure but i have to make one query instead of two views...
I know how to create a stored procedure but i have to make one query instead of two views...
Then I don't understand why this -
-
SELECT The,FIELDS,You,Want
-
FROM View1
-
TheJoinType View2 ON TheJoinCriteria
-
didn't answer your question
i have made 2 views and concted them and my query is working find, but i want to make a 1 stored procedure from these 2 views ... View 1
SELECT dbo.page_information.page_id
FROM dbo.user_pages INNER JOIN
dbo.page_information ON dbo.user_pages.page_id = dbo.page_information.page_id
WHERE (dbo.user_pages.e_id = 32) View 2
SELECT dbo.page_information.page_id AS Expr1
FROM dbo.VIEW1 RIGHT OUTER JOIN
dbo.page_information ON dbo.VIEW1.page_id = dbo.page_information.page_id
WHERE (dbo.VIEW1.page_id IS NULL)
Please can u hlp me out
Your View2 will always be empty. Why? Because you have a WHERE (dbo.user_pages.e_id = 32) condition on your View1.Since it's an INNER JOIN, your dbo.page_information.page_id in view1 will always be 32 which means this WHERE (dbo.VIEW1.page_id IS NULL) will always be FALSE
-- ck
The query I gave wasn't meant to be used as is, I meant it as an example of how to join the two views together for use in a stored procedure.
Thats why I used generic terms instead of specific fields :-)
If the fields in the views aren't compatible for joining then you will need to provide fields in them that are. maybe you could do something such as -
View 1
-
SELECT 1 as J,dbo.page_information.page_id
-
FROM dbo.user_pages INNER JOIN
-
dbo.page_information ON dbo.user_pages.page_id = dbo.page_information.page_id
-
WHERE (dbo.user_pages.e_id = 32)
-
-
-
View 2
-
SELECT 1 as J,dbo.page_information.page_id AS Expr1
-
FROM dbo.VIEW1 RIGHT OUTER JOIN
-
dbo.page_information ON dbo.VIEW1.page_id = dbo.page_information.page_id
-
WHERE (dbo.VIEW1.page_id IS NULL)
-
then you could join the two queries on field J.
I don't know, this is meant as a suggestion not a total solution to your specific problem. If the Idea helps then you will need to adjust it to suit your specific requirements. There is not enough info to provide any more that suggestions
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Mike N. |
last post by:
Hello:
I am new to T-SQL programing, and relativly new to SQL statements in
general, although I have a good understanding of database theory. I'm a
little confused as to the fundamental...
|
by: Ryan.Chowdhury |
last post by:
This is a general question regarding the use of view and stored
procedures. I'm fairly new to databases and SQL.
I've created a SQL database using an Access Data Project ("ADP") and
I'm...
|
by: Mike |
last post by:
Hello,
I have a few rather urgent questions that I hope someone can help with (I
need to figure this out prior to a meeting tomorrow.) First, a bit of
background: The company I work for is...
|
by: Dave Stone |
last post by:
I've just installed SP3A on MSDE 2000 since when any projects I open
have a database window which (under 'Objects') lists Database
Diagrams, but not Views or Stored Procedures. Has anyone else seen...
|
by: billmiami2 |
last post by:
Perhaps many of you MS Access fanatics already know this, but it seems
that stored procedures and views are possible in Jet. I thought I
would leave this message just in case it would help anyone....
|
by: T.S.Negi |
last post by:
Hello All,
I want to Find out list of tables, views and stored procedure used in vb form.
If any body have any idea about it, pls.let me know.
Thanx in adv.
T.S.Negi
|
by: Jack |
last post by:
Hi all,
While debugging some old code from someone, I came across this stored
procedure:
SELECT dbo.TBL_COORD.COORD_ID AS ID, dbo.TBL_COORD.LATITUDE AS Latitude,
dbo.TBL_COORD.LONGITUDE AS...
|
by: mooreit |
last post by:
The purpose for my questions is accessing these technologies from
applications. I develop both applications and databases. Working with
Microsoft C#.NET and Microsoft SQL Server 2000 Production and...
|
by: Mike S |
last post by:
Hi all,
A (possibly dumb) question, but I've had no luck finding a definitive
answer to it. Suppose I have two tables, Employees and Employers, which
both have a column named "Id":
Employees...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |