Alternative To Joining Views

Dec 4, 2006

Hi,

I have 2 views that I can join to give me the recordset I want. Both views are currently filtered on a particular column (ie 'WHERE colName = myValue')

The problem is that I want to use this from a web page with user input in which the user would specify myValue.

Is there any alternative to having two views? Can I combine them into one SQL statement? Access allowed me to do it by specifying an alias for a select statement, then joining this to another. I'm not sure if that makes sense, but I guess what I want to do it specify one view then another, then join them - all in the same statement!

Something like this:


Code:

SELECT view1.*, view2.*
FROM ((SELECT tbl1.*,tbl2.*,tbl3.*
FROM tbl1 JOIN tbl2 ON tbl1.id = tbl2.tbl1_id
JOIN tbl3 ON tbl2.id = tbl3.tbl2_id
AND tbl3.id = myValue) AS view1)
((SELECT tbl4.* FROM tbl4 WHERE tbl4.id = myValue) AS view2)
RIGHT JOIN view1 ON view2....

View 1 Replies


ADVERTISEMENT

Joining 2 Views

Feb 27, 2008

Hi, I am new to sql and I am trying to join 2 views using MySQL Query Browser. Here is my query and the issues I am having.

SELECT book_month, region_book, product_group as base_prod_group, cnt as base_cnt FROM collections.v_nonpay_trend_base a
join collections.v_nonpay_trend_npdata b
on (a.book_month=b.disc_check_in_month and a.region_book=b.region and a.base_prod_group=b.product_group)

Error - "Column 'product_group' in field list is ambiguous" and "Column 'cnt' in field list is ambiguous"

Both views have columns named 'product_group' and 'cnt'

Can someone please let me know what I am doing wrong?

Thanks!!

View 2 Replies View Related

Joining Views

Mar 6, 2008

create view myidtitlenew
as
SELECT c1.messageid_,
c1.title_, c1.list_,
c1.created_
FROM outmail_ c1
inner join (Select max(messageid_) as messageid_, max(title_) as title_
FROM outmail_ c1 where list_ = 'copd'
GROUP BY substring([title_],1,charindex(' ',[title_])-1)
) c2

ON c1.messageid_ = c2.messageid_
go

create view mymembersum
as
select distinct list_, membertype_ , count(*) as cnt
from Members_ where list_='copd'
group by membertype_,list_
go

how could i join them?

View 6 Replies View Related

Problem Joining 2 Views

May 10, 2007

Hi guys,I detected a strange behaviour when doing an inner join of two views.There is table_Objects, table_Contracts and view_Objects, View_Contracts.Table_Objects: ID, PriceView_Objects: Select * from Table_Objects Where Price > 10Table_Contracts: ID, YearView_Contracts: Select c.ID, c.YearFrom Table_Contracts c Join View_Objects o on c.id=o.idQuiete simple so far, but it doesn't work. Imagine Object with id 3 that is shown in View_Objects and Table_Contracts but not shown in View_Contracts. How is that possible?EDIT: Sometimes its shown, sometimes notThx for your reply!

View 3 Replies View Related

SQL-Query Mindbugger Joining A 2 Views

Oct 23, 2006

Ok, What I want to achieve is plain stuff, I want to join 2 views on a common key.It all works well with the SQL2000 Query Analyzer, but not trough ADO.NET or should I say my webapplication.With that I mean that my query return rows when executed from SQL2000 Query Analyzer, But not when used in my application or Executed from the Visual Studio Server Explorer.I have struggled with this one for several hours, I cant get this one right.So lets bring in the one who actually know what his doing View1: 1 select
2 cast((PS.RabattProsent/100.00)*PS.Pris AS decimal(11,2)) AS Rabatt
3 ,cast((PS.MVAProsent/100.00)*PS.Pris AS decimal(11,2)) AS MVA
4 ,cast(PS.Antall * ((PS.Pris*(100-PS.RabattProsent))/100)*((PS.MvaProsent/100.00)+1) AS decimal(11,2)) AS Belop
5 ,PS.*
6 ,K.Kunde_ID
7 FROM
8 tbl_ProduktSalg AS PS
9 INNER JOIN
10 tbl_Ordre AS O
11 ON
12 O.Ordre_ID = PS.Ordre_ID
13 INNER JOIN
14 tbl_Kunde AS K
15 ON
16 K.Kunde_ID = O.Kunde_IDView2: 1 SELECT
2 PS.Ordre_ID
3 ,SUM(cast((PS.RabattProsent/100.00)*PS.Pris AS decimal(11,2))) AS TotalRabatt
4 ,SUM(cast(PS.Antall * ((PS.Pris*(100-PS.RabattProsent))/100)*((PS.MvaProsent/100.00)+1) AS decimal(11,2))) AS TotalBelop
5 ,SUM(PS.Pris) AS TotalPris
6 ,SUM(cast((PS.MVAProsent/100.00)*PS.Pris AS decimal(11,2))) AS TotalMVA
7 FROM
8 tbl_ProduktSalg AS PS
9 GROUP BY
10 PS.Ordre_ID
   MyQuery/SPRC: 1 create procedure %PROC% (@Kunde_ID int, @Ordre_ID int)
2 as
3 begin
4 SELECT
5 v_PSD.*
6 ,v_OTS.TotalRabatt
7 ,v_OTS.TotalBelop
8 ,v_OTS.TotalPris
9 ,v_OTS.TotalMVA
10 FROM
11 v_ProduktSalgDetaljer AS v_PSD
12 INNER JOIN
13 v_OrdreTotalSum AS v_OTS
14 ON
15 v_OTS.Ordre_ID = v_PSD.Ordre_ID
16 WHERE
17 v_PSD.Kunde_ID = @Kunde_ID
18 AND
19 v_PSD.Ordre_ID = @Ordre_ID
20
21 end
22
  

View 3 Replies View Related

Joining Views && Query Performance

May 1, 2006

Over the years I've read and experienced where joining more then 5 tables can lead to performance problems. This number can vary based upon the amount of data in each table, if and how indexes are used and the complexity of the query, but 5 has always been a good rule of thumb. Unfortunately I do not know what rule to apply in regards to joing views.

A developer has experienced timeout problems periodically when opening a view in EM or when running the code which makes-up the view. I decided to look at the view and noticed it references tables and views, which reference more views, which in turn reference other views. In all the initial view references 5 tables and 8 views directly and indirectly, with some of the views containing function calls. What are your thoughts on how many views and tables are too many when it comes to joins and query performance.

Thanks, Dave

View 6 Replies View Related

DB Engine :: Joining 3 Or More Multi-tables Using Views

Sep 8, 2015

I am new to programming trying hard to learn. I made a code for Views in mssql for the 2 tables below:I am wondering if I could make it 3, 4 or more tables at the same time. How can incorporate in the following codes I made.

Create View vwEmployeeInfoByGender
as
Select FirstName, MiddleName, FamilyName, Gender, BirthDate,
MaritalStatus
from tblEmployeeInfo
join tblGender
on tblEmployeeInfo.GenderID
= tblGender.GenderID

View 26 Replies View Related

Are Embedded Views (Views Within Views...) Evil And If So Why?

Apr 3, 2006

Fellow database developers,I would like to draw on your experience with views. I have a databasethat includes many views. Sometimes, views contains other views, andthose views in turn may contain views. In fact, I have some views inmy database that are a product of nested views of up to 6 levels deep!The reason we did this was.1. Object-oriented in nature. Makes it easy to work with them.2. Changing an underlying view (adding new fields, removing etc),automatically the higher up views inherit this new information. Thismake maintenance very easy.3. These nested views are only ever used for the reporting side of ourapplication, not for the day-to-day database use by the application.We use Crystal Reports and Crystal is smart enough (can't believe Ijust said that about Crystal) to only pull back the fields that arebeing accessed by the report. In other words, Crystal will issue aSelect field1, field2, field3 from ReportingView Where .... eventhough "ReportingView" contains a long list of fields.Problems I can see.1. Parent views generally use "Select * From childview". This meansthat we have to execute a "sp_refreshview" command against all viewswhenever child views are altered.2. Parent views return a lot of information that isn't necessarilyused.3. Makes it harder to track down exactly where the information iscoming from. You have to drill right through to the child view to seethe raw table joins etc.Does anyone have any comments on this database design? I would love tohear your opinions and tales from the trenches.Best regards,Rod.

View 15 Replies View Related

Large Views Vs Multiple Small Views

Sep 6, 2007

Which is more efficient? One large view that joins >=10 tables, or a few smaller views that join only the tables needed for individual pages?

View 1 Replies View Related

Recompiling Views That Reference Other Views

Jun 28, 2007

Hello.

Newbie here. I've only been using SQL for about a year now and have some minor questions about sql objects that reference other objects.



We have some views which reference other views in the joins. I will call one the primary view and the one being referenced in the joins as the secondary view.

Recently we made changes to the secondary view.

After which the primary views which referenced it would not work because of this change and had to be 'refreshed' by using drop/create scripts which essentially just dropped it and recreated the exact same view. I do not recall the exact error message that was returned other than it seemed to suggest that it could no longer see the secondary view since it had been changed. Nothing in the primary view was changed in any way, just the secondary.



Some here where I work have suggested off hand that this was a recompile of the primary view because the contents of the secondary changed.

My questions are:

1. Exactly why did this happen and is there a proper name for it when it does?

2. The same problem does not seem to occur when we have stored procedures referencing views in the joins which had just been changed. Why is that?



Thanks for any help on the matter. I greatly appreciate it.

View 3 Replies View Related

Quicky : Views Of Views Of Views

Feb 22, 2007

Hello,

to make a report easier I'm developing it using a view of joined views of joined views.

Is there any significant performance penalty as opposed to just having one big select?

Cheers.

View 1 Replies View Related

Alternative For DTC

Jul 30, 2007

Hi,
i am using the DTC in my code to connect to two different servers on the network through a SQL query which is unfortunately very slow; can u please guide me with an alternative for the same

Thanks

View 17 Replies View Related

Alternative Way

Jul 20, 2005

SELECT *FROM organizationWHERE (departmentID = divisionID) AND (divisionID = branchID) AND(branchID = sectionID) AND (sectionID = unitID)Is there anyway I can make this query more simlified w/o repeating thesame column in the where clause?thankss/RC

View 3 Replies View Related

@@IDENTITY Alternative

Dec 30, 2007

Hi everyone,
I'm trying to come up with a replacement for @@IDENTITY, because I have SQL code I want to make more portable.

Original:ID = MyDataLayer.Execute("INSERT INTO X(a,b,c) VALUES(A,B,C); SELECT @@IDENTITY")
Proposed solution:
lock(MyDataLayer)
ID = MyDataLayer.Execute("SELECT MAX(id)+1 FROM X")
if(ID==null) ID=1
MyDataLayer.Execute("INSERT INTO X(id,a,b,c) VALUES(ID,A,B,C)")
unlock(MyDataLayer)
(This is of course pseudocode, for SQL Server I'd need SET IDENTITY_INSERT.)

Do you think the preceding solution is equivalent to the original?
Do you know something better?

Equivalent should mean here, not necessarily generating the same ID's,
but maintaining functionality and consistence all over the database.

View 9 Replies View Related

Alternative To Using USE In A PROCEDURE

Apr 7, 2004

is there a way to get around not using USE in a PROCEDURE?

I need to because I have a main site that inserts information into other DB's that i use for various subdomains. But without being able to use USE i cant select which database is needed.

thx in advance

View 2 Replies View Related

Immediate IF ALTERNATIVE REQUIRED

May 14, 2001

Hi!

I wrote a query in MS-ACCESS using IIF. Is there any way to convert it to SQL Server Query to do the same job as it do in MS-ACCEESS

e.g. Here is manipulation with one column that I did in MS-ACCESS

IIf(InStr(1,Destinations.[Destination Name],"-",1)-1<0,Destinations.[Destination Name],Left(Destinations.[Destination Name],InStr(1,Destinations.[Destination Name],"-",1)-1)) AS COUNTRY,

View 1 Replies View Related

MSDE Alternative

Jan 26, 2004

My company develops software that is distributed to thousands of customers. We chose MSDE as the database engine. Over the past 4 months, we have spent countless hours with customers, Microsoft, Installshield and web searches trying to resolve issues with installing MSDE. The issues seem to vary by customer and most take a great deal of support time. We understood MSDE to be a product that requires little support but in hindsight, it appears that it requires a great deal of knowledge just to get installed. We make small steps but no leaps forward.

It has come time to evaluate other products. If there is a magic bullet, I would love to hear about it. In its absence, does anyone have success to share with other products?

Phil

View 13 Replies View Related

Alternative To SQLXMLBULKLOAD ?

May 2, 2008

Hi,

Just curious, is there any alternative to SQLXMLBULKLOAD for shredding and loading very large (800 megs) XML files ? Due to the nature of the XML data sent to me (which I have no control over)I am having great difficulty loading data into tables. More specifically, I can load parent data but not the child data beneath it despite using sql:relationships.

Thanks,
Jeff

View 2 Replies View Related

Cursor Alternative ?

Mar 30, 2006

Hi,

In a stored procedure I'm processing, via a cursor, a table of, potentially, 100,000 rows on a daily basis. The only column in each row is a 12-byte transaction control number. I know that using cursors can cause performance issues. Is there an alternative to using a cursor that has less of a performance impact ?

Thanks,
Jeff

View 5 Replies View Related

Alternative To Cursor..

Jul 18, 2006

Hi All,

Beside cursor, what else can i use to speed up my processing? Now i have about 2mils rows need to update using one daily reference table(30k rows).

Thanks,
Jack

View 10 Replies View Related

Index Alternative

Feb 14, 2007

Cameron writes "Thanks for taking a look @ my question....

Basically, is there an alternative to indexing that maintains the fast searching capability (or possibly faster)?

We maintain over 500 databases on a single SQL server and currently (the way I am told) the server is limited to indexing 256 databases, so we have to basically create a new database with ALL the searchable data and use it for searches. While this works, it seems like there should be an alternate method. Any suggestions?

Thank you for your time!"

View 3 Replies View Related

Alternative To ODBC

Mar 1, 2007

are there any alternatives to linking my db to webserver other then ODBC such as direct dsn connection

View 4 Replies View Related

Alternative To Sqlvarient

Sep 24, 2007

i need some alternative to sqlvarient..

View 2 Replies View Related

Alternative To IF In This Case

Oct 24, 2007

Hey guys,
What would be a better / more elegant solution to something like

IF(@areaCode = '111' OR @areaCode = '222' 0R @areaCode = '333')
BEGIN
//do something
END

that uses less OR's in an IF statement?

View 6 Replies View Related

Alternative To Triggers

Feb 1, 2008

Hi all

I work as a production dba and our development team are trying to push a project which involves using triggers. The aim is to transfer information between to databases (on two differents servers) because currently users have to type in the same info into the two different systems.
The triggers will be defined on a couple of tables, checking for inserts, updates, deletes, and then insert this into staging tables within teh same database. However the trigger does more complex processing than just inserting the same records from the production table into the staging table. Because the schema between the source database and destination database is different, the trigger needs to do some manipulation before it updates the staging tables. It basically does massive selects from a number of different tables to get the desired column list & then puts that into the staging tables.
We have basically asked them to reimplement this solution using other methods (such as timestamping the necessary tables and then putting the trigger login into a stored proc and scheduling it to run through a job).

However, we've found out the triggers make use of the 'deleted' and 'inserted' special trigger tables to compare new data to old data - i.e. not all inserts/updates/deletes need to be pushed to the staging tables - it depends on certain criteria based on this comparison of old and new data.....that throws a spanner in the works. What alternatives could provide this functionality, without just making the whole process a a headache to maintain - which is why we recommended not using triggers in the first place!!

Sorry for the long post - needed to explain the issue properly. Hopefully some of you will be able to provide some feedback - teh sooner the better as I have a meeting with the developers later today and would like to offer some alternatives.

Thanks!
Div

View 2 Replies View Related

Alternative To OpenXML

Mar 17, 2006

Hi All,I want to pass XML and the data in the XML should be stored in thetables of the database. However, I do not want to use the OpenXMLstatement. Please let me know.Regards, Shilpa

View 2 Replies View Related

Alternative To Dynamic Sql?

Jul 20, 2005

I have a procedure that take several paramters and depending of whatvalues is submitted or not, the procedures shall return differentnumber of rows. But to simplyfy this my example use just oneparameter, for example Idnr.If this id is submitted then I will return only the posts with thisidnr, but if this is not submitted, I will return all posts in table.As I can see I have two options1. IF @lcIdNr IS NOT NULLSELECT *FROM tableWHERE idnr = @lcIdNrELSESELECT *FROM table2. Use dynamic SQL.The first example can work with just one parameter but with a coupleof different input paramters this could be difficult, anyway this isnot a good solution. The second example works fine but as I understanddynamic sql is not good from the optimizing point of view. So, I don'twant to use either of theese options, so I wonder If there i a way towork around this with for example a case clause?RegardsJenny

View 3 Replies View Related

Alternative To Identity Help.

Aug 20, 2007




I have a SSIS package that imports an Excel file using Visual Basic 2005 into my SQL 2005 database. All the fields are the same in the DB and xls. The package runs with no problem but I need one of the fields to be autoincrement. I tried to set up the properties of one of my fields "ID" to be an Identity. This didn't seem to work at all. There are about 1300 records in the DB so far with the last "ID" number being 10001415. Before now, the numbers were inputed manually. I want the "ID" to be assigned when the SSIS package imports the xls file.


Any help is very appreciated.

View 8 Replies View Related

SCD Component - Is There An Alternative?

Nov 21, 2006

Hi,

I have several SCD components in my project. As I have to process millions of records, SCD's are taking a lot of time. Is there a way to speed them up? Work arounds?

Any tip is welcome

-Tom

View 21 Replies View Related

What Is The Alternative To Go Under Sqlcmd?

Oct 8, 2006

Hi

I found it a bit annoying to type Go after some very simple query and I wonder is there a short cut to execute the query i type right after I press enter?

1> select * from Table
2> go <enter>

instead, how to you execute line 1 without entering go?

Thank you

View 7 Replies View Related

Anoter Alternative

Jul 27, 2007

There is another alternative ... if you are using MSCRM 3.0

follow this steps

1. Navigate to your report manager --> //<<Server Name>>/reports
2. Navigate to your datasource --> HOME > <<Datasource>>
3. At the top tab select Properties
4. Make sure that there is a user role call "NT AUTHORITYNETWORK SERVICE" thus apply the appropiate roles for it


Vula....!!!!!

View 1 Replies View Related

IF ELSE Alternative For Stored Procedure

May 1, 2007

Hi,I'm trying to create a stored procedure that checks to see whether the parameters are NULL. If they are NOT NULL, then the parameter should be used in the WHERE clause of the SELECT statement otherwise all records should be returned.sample code: SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[GetProjectInfo]
(@ProjectTitle varchar(300), @ProjectManagerID int, @DeptCode varchar(20), @ProjID varchar(50),
@DateRequested datetime, @DueDate datetime, @ProjectStatusID int)
AS
BEGIN
SET NOCOUNT ON
IF @ProjectTitle IS NOT NULL AND @ProjectManagerID IS NULL AND @DeptCode IS NULL AND @ProjID IS NULL AND @DateRequested IS NULL AND @DueDate IS NULL AND @ProjectStatusID IS NULL
SELECT ProjID, ProjectTitle, ProjectDetails, ProjectManagerID, RequestedBy, DateRequested, DueDate, ProjectStatusID
FROM dbo.tbl_Project
WHERE ProjectTitle = @ProjectTitle;
ELSE IF @ProjectTitle IS NOT NULL AND @ProjectManagerID IS NOT NULL AND @DeptCode IS NULL AND @ProjID IS NULL AND @DateRequested IS NULL AND @DueDate IS NULL AND @ProjectStatusID IS NULL
SELECT ProjID, ProjectTitle, ProjectDetails, ProjectManagerID, RequestedBy, DateRequested, DueDate, ProjectStatusID
FROM dbo.tbl_Project
WHERE ProjectTitle = @ProjectTitle AND ProjectManagerID = @ProjectManagerID;
ELSE
SELECT ProjID, ProjectTitle, ProjectDetails, ProjectManagerID, RequestedBy, DateRequested, DueDate, ProjectStatusID
FROM dbo.tbl_Project; I could do this using IF-ELSE but that would require a ridiculous amount of conditional statements (basically 1 for each combination of NULLs and NOT NULLs). Is there a way to do this without all the IF-ELSEs? Thanks. 

View 34 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved