473,395 Members | 2,423 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Join these 2 views and make one stored procedure

4
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
Expand|Select|Wrap|Line Numbers
  1. SELECT     dbo.page_information.page_id
  2. FROM         dbo.user_pages INNER JOIN
  3.                       dbo.page_information ON dbo.user_pages.page_id = dbo.page_information.page_id
  4. WHERE     (dbo.user_pages.e_id = 32)
View 2
Expand|Select|Wrap|Line Numbers
  1. SELECT     dbo.page_information.page_id AS Expr1
  2. FROM         dbo.VIEW1 RIGHT OUTER JOIN
  3.                       dbo.page_information ON dbo.VIEW1.page_id = dbo.page_information.page_id
  4. WHERE     (dbo.VIEW1.page_id IS NULL)
Please can u hlp me out
Jan 20 '08 #1
10 5925
ck9663
2,878 Expert 2GB
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
Jan 20 '08 #2
drweb
4
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.
Jan 20 '08 #3
Delerna
1,134 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1. SELECT The,Fields,You,Want
  2. FROM View1
  3. TheJoinType View2 ON TheJoinCriteria
  4.  
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

Expand|Select|Wrap|Line Numbers
  1. SELECT The,Fields,You,Want
  2. FROM
  3. (   SELECT dbo.page_information.page_id
  4.     FROM dbo.user_pages 
  5.     INNER JOIN dbo.page_information 
  6.     ON dbo.user_pages.page_id =dbo.page_information.page_id
  7.     WHERE (dbo.user_pages.e_id = 32)
  8. ) a
  9.  
  10. JOIN
  11.  
  12. (   SELECT dbo.page_information.page_id AS Expr1
  13.     FROM dbo.VIEW1 
  14.     RIGHT OUTER JOIN dbo.page_information 
  15.     ON dbo.VIEW1.page_id = dbo.page_information.page_id
  16.     WHERE (dbo.VIEW1.page_id IS NULL)
  17. ) b
  18. ON a.JoinField=b.JoinField
  19.  
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
Jan 20 '08 #4
ck9663
2,878 Expert 2GB
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
Jan 21 '08 #5
drweb
4
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
Jan 21 '08 #6
ck9663
2,878 Expert 2GB
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
Jan 21 '08 #7
drweb
4
I know how to create a stored procedure but i have to make one query instead of two views...
Jan 22 '08 #8
Delerna
1,134 Expert 1GB
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
Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT The,FIELDS,You,Want
  3. FROM View1
  4. TheJoinType View2 ON TheJoinCriteria
  5.  
didn't answer your question
Jan 22 '08 #9
ck9663
2,878 Expert 2GB
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
Jan 22 '08 #10
Delerna
1,134 Expert 1GB
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
Expand|Select|Wrap|Line Numbers
  1. View 1 
  2. SELECT 1 as J,dbo.page_information.page_id
  3. FROM dbo.user_pages INNER JOIN
  4. dbo.page_information ON dbo.user_pages.page_id = dbo.page_information.page_id
  5. WHERE (dbo.user_pages.e_id = 32)
  6.  
  7.  
  8. View 2 
  9. SELECT 1 as J,dbo.page_information.page_id AS Expr1
  10. FROM dbo.VIEW1 RIGHT OUTER JOIN
  11. dbo.page_information ON dbo.VIEW1.page_id = dbo.page_information.page_id
  12. WHERE (dbo.VIEW1.page_id IS NULL)
  13.  
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
Jan 23 '08 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

8
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...
3
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...
8
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...
2
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...
0
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....
4
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
4
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...
28
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...
6
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...
0
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...
0
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
1
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...
0
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...
0
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...
0
Oralloy
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,...
0
jinu1996
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...
0
tracyyun
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...
0
agi2029
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.