Showing posts with label returned. Show all posts
Showing posts with label returned. Show all posts

Wednesday, March 28, 2012

Incorrect value returned from Stored Procedure

I have an asp.net 1.1 website that uses sql server 2000 and vb.

I have a bit of a dilema, when I run a stored procedure in a webpage it returns the wrong value, but if I run it

in the query analyzer the correct value is returned.

 Dim orderHistory As nlb.OrdersDB = New nlb.OrdersDB ' Obtain Order ID from QueryString Dim OrderID As Integer = CInt(Request.Params("ID")) ' Get the customer ID too Dim myNewCustomerId As Integer = 0 myNewCustomerId = orderHistory.GetOrderCustomer(OrderID) Public Function GetOrderCustomer(ByVal orderID As Integer) As Integer ' Create Instance of Connection and Command Object Dim myConnection As SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings("ConnectionString")) Dim myCommand As SqlCommand = New SqlCommand("nlbsp_OrdersCustomerID", myConnection) ' Mark the Command as a SPROC myCommand.CommandType = CommandType.StoredProcedure ' Add Parameters to SPROC Dim parameterOrderID As New SqlParameter("@.order_id", SqlDbType.Int, 4) parameterOrderID.Value = orderID myCommand.Parameters.Add(parameterOrderID) Dim parameterOrderCustID As New SqlParameter("@.customer_id", SqlDbType.Int, 4) parameterOrderCustID.Value = ParameterDirection.Output myCommand.Parameters.Add(parameterOrderCustID) 'Open the connection and execute the Command myConnection.Open() myCommand.ExecuteNonQuery() myConnection.Close() ' Return the customer_id (obtained as out paramter of SPROC) If parameterOrderCustID.Value <> 0 Then Return CInt(parameterOrderCustID.Value) Else Return 0 End If End Functionthe stored procdure isCREATE PROCEDURE [dbo].[nlbsp_OrdersCustomerID]( @.order_id int, @.customer_id int OUTPUT)AS/* Return the customer_id from the Orders. */SELECT @.customer_id = customer_id FROM nlb_Orders WHERE order_id = @.order_idGO

I know a particular order_id returns a value of 1. But when I run it in the webpage it always comes back as 2.

Any ideas would be appreciated

Thanks

Pete

Seems you made a small mistake:

parameterOrderCustID.Value = ParameterDirection.Output

It should be:

Dim CustomerID As Integer
parameterOrderCustID.Value = CustomerID
parameterOrderCustID.Direction=ParameterDirection.Output

Wednesday, March 21, 2012

Incorrect results if no TOP clause

I have a problem with a query. When I omit the TOP clause I get more
rows returned than I expect (12 rows out of a 119 in the table), but
when I include TOP I get 5 rows from the same data with the otherwise
unchanged table.
Thing is, the query where I include TOP 1000 is the correct result.
I'm on SQL Server 2000, select @.@.version -
"Microsoft SQL Server 2000 - 8.00.194 (Intel X86) Aug 6 2000
00:57:48 Copyright (c) 1988-2000 Microsoft Corporation Developer
Edition on Windows NT 5.1 (Build 2600: Service Pack 1) "
I've cut the query down quite a bit, the table
create table Test (
CDMA_PDSN63 FLOAT,
AVE__CORE_46_CountINTEGER,
AVE__CORE_46_Sum FLOAT);
The query is
SELECT * FROM (
SELECT
-- TOP 1000 -- comment this in to get correct results
D.CDMA_PDSN63, NM.AVE__CORE_46x AVE__CORE_46
FROM (SELECT DISTINCT CDMA_PDSN63
FROM(SELECT CDMA_PDSN63 FROM Test ) AS dims
) AS D,
(SELECT CDMA_PDSN63,
CASE when (Sum( AVE__CORE_46_Count))=0 then NULL else
SUM(AVE__CORE_46_Sum) / SUM( AVE__CORE_46_Count) end AS AVE__CORE_46x
FROM Test GROUP BY CDMA_PDSN63) AS NM
WHERE D.CDMA_PDSN63*=NM.CDMA_PDSN63
) as MainQuery
WHERE ROUND(MainQuery.AVE__CORE_46,0) >= 120
--AND MainQuery.AVE__CORE_46 IS NOT NULL - Note 1
--ORDER BY CDMA_PDSN63 - Note 2
Note 1: I tried adding this but it makes not difference
Note 2: this was in the original query, it makes sense to have it but
again it makes no difference, I've used in on the inner and outer
select, no change
I've also tried TOP 1000 in the outer select again no difference.
Changing the outer join to a regular join fixes the problem, but I
need the outer join in the original query. (In the original query
there are many more sub-selects and several more outer join clauses to
put them back together.)
If I use small values for TOP n (e.g. 1, 2, ... < 10) the results are
even stranger, I get a subset of the expected rows, and not the same
number as n.
I tried setting a rowcount as well, no difference.
I've seen several other queries on this newsgroup which talk about
similar problems but the threads have never been concluded with a
clear answer.
Any ideas? Thanks
allan
> "Microsoft SQL Server 2000 - 8.00.194
You're on RTM! Install Service Pack 3a, right away, please! There are many
query processor bugs that have been fixed since the product was released.
Thanks for the CREATE TABLE, but once you've done that, you're going to have
to provide us with enough sample data to reproduce your problem (as well as
tell us which rows you were expecting in the result set!). Otherwise, it's
impossible for us to determine exactly what's happening, why it doesn't meet
your criteria, and test our suggestions on fixing it...
See http://www.aspfaq.com/5006
http://www.aspfaq.com/
(Reverse address to reply.)
|||Allan,
After you install service pack 3a as Aaron suggested, I suggest you
consider two other things:
* Rwrite the query using ANSI outer join syntax (... left outer join on
...), which, unlike *=, is always unambiguous
* Consider a different data type than FLOAT for data that must be
compared with the = operator. Because FLOAT values are approximate, you
cannot count on tests of equality to be reliable.
Steve Kass
Drew University
Allan Kelly wrote:

>I have a problem with a query. When I omit the TOP clause I get more
>rows returned than I expect (12 rows out of a 119 in the table), but
>when I include TOP I get 5 rows from the same data with the otherwise
>unchanged table.
>Thing is, the query where I include TOP 1000 is the correct result.
>I'm on SQL Server 2000, select @.@.version -
>"Microsoft SQL Server 2000 - 8.00.194 (Intel X86) Aug 6 2000
>00:57:48 Copyright (c) 1988-2000 Microsoft Corporation Developer
>Edition on Windows NT 5.1 (Build 2600: Service Pack 1) "
>I've cut the query down quite a bit, the table
>create table Test (
>CDMA_PDSN63 FLOAT,
>AVE__CORE_46_CountINTEGER,
>AVE__CORE_46_Sum FLOAT);
>The query is
>SELECT * FROM (
>SELECT
>-- TOP 1000 -- comment this in to get correct results
>D.CDMA_PDSN63, NM.AVE__CORE_46x AVE__CORE_46
>FROM (SELECT DISTINCT CDMA_PDSN63
>FROM(SELECT CDMA_PDSN63 FROM Test ) AS dims
>) AS D,
>(SELECT CDMA_PDSN63,
>CASE when (Sum( AVE__CORE_46_Count))=0 then NULL else
>SUM(AVE__CORE_46_Sum) / SUM( AVE__CORE_46_Count) end AS AVE__CORE_46x
>FROM Test GROUP BY CDMA_PDSN63) AS NM
>WHERE D.CDMA_PDSN63*=NM.CDMA_PDSN63
>) as MainQuery
>WHERE ROUND(MainQuery.AVE__CORE_46,0) >= 120
>--AND MainQuery.AVE__CORE_46 IS NOT NULL - Note 1
>--ORDER BY CDMA_PDSN63 - Note 2
>Note 1: I tried adding this but it makes not difference
>Note 2: this was in the original query, it makes sense to have it but
>again it makes no difference, I've used in on the inner and outer
>select, no change
>I've also tried TOP 1000 in the outer select again no difference.
>Changing the outer join to a regular join fixes the problem, but I
>need the outer join in the original query. (In the original query
>there are many more sub-selects and several more outer join clauses to
>put them back together.)
>If I use small values for TOP n (e.g. 1, 2, ... < 10) the results are
>even stranger, I get a subset of the expected rows, and not the same
>number as n.
>I tried setting a rowcount as well, no difference.
>I've seen several other queries on this newsgroup which talk about
>similar problems but the threads have never been concluded with a
>clear answer.
>Any ideas? Thanks
>allan
>
|||Steve Kass <skass@.drew.edu> wrote in message news:<#Tj3pA0dEHA.1604@.TK2MSFTNGP11.phx.gbl>...
> Allan,
> After you install service pack 3a as Aaron suggested, I suggest you
> consider two other things:
> * Rwrite the query using ANSI outer join syntax (... left outer join on
> ...), which, unlike *=, is always unambiguous
> * Consider a different data type than FLOAT for data that must be
> compared with the = operator. Because FLOAT values are approximate, you
> cannot count on tests of equality to be reliable.
>
Thanks Aaron, Steve,
I rewrote the SQL using ANSI outer join syntax and that fixes the
problem. Great!
Thanks for the reminder to look into the service pack, my code need to
run against MSDE in the final product so I need to check out the
service pack situation there.
allan

Incorrect results if no TOP clause

I have a problem with a query. When I omit the TOP clause I get more
rows returned than I expect (12 rows out of a 119 in the table), but
when I include TOP I get 5 rows from the same data with the otherwise
unchanged table.
Thing is, the query where I include TOP 1000 is the correct result.
I'm on SQL Server 2000, select @.@.version -
"Microsoft SQL Server 2000 - 8.00.194 (Intel X86) Aug 6 2000
00:57:48 Copyright (c) 1988-2000 Microsoft Corporation Developer
Edition on Windows NT 5.1 (Build 2600: Service Pack 1) "
I've cut the query down quite a bit, the table
create table Test (
CDMA_PDSN63 FLOAT,
AVE__CORE_46_Count INTEGER,
AVE__CORE_46_Sum FLOAT);
The query is
SELECT * FROM (
SELECT
-- TOP 1000 -- comment this in to get correct results
D.CDMA_PDSN63, NM.AVE__CORE_46x AVE__CORE_46
FROM (SELECT DISTINCT CDMA_PDSN63
FROM(SELECT CDMA_PDSN63 FROM Test ) AS dims
) AS D,
(SELECT CDMA_PDSN63,
CASE when (Sum( AVE__CORE_46_Count))=0 then NULL else
SUM(AVE__CORE_46_Sum) / SUM( AVE__CORE_46_Count) end AS AVE__CORE_46x
FROM Test GROUP BY CDMA_PDSN63) AS NM
WHERE D.CDMA_PDSN63*=NM.CDMA_PDSN63
) as MainQuery
WHERE ROUND(MainQuery.AVE__CORE_46,0) >= 120
--AND MainQuery.AVE__CORE_46 IS NOT NULL - Note 1
--ORDER BY CDMA_PDSN63 - Note 2
Note 1: I tried adding this but it makes not difference
Note 2: this was in the original query, it makes sense to have it but
again it makes no difference, I've used in on the inner and outer
select, no change
I've also tried TOP 1000 in the outer select again no difference.
Changing the outer join to a regular join fixes the problem, but I
need the outer join in the original query. (In the original query
there are many more sub-selects and several more outer join clauses to
put them back together.)
If I use small values for TOP n (e.g. 1, 2, ... < 10) the results are
even stranger, I get a subset of the expected rows, and not the same
number as n.
I tried setting a rowcount as well, no difference.
I've seen several other queries on this newsgroup which talk about
similar problems but the threads have never been concluded with a
clear answer.
Any ideas? Thanks
allan> "Microsoft SQL Server 2000 - 8.00.194
You're on RTM! Install Service Pack 3a, right away, please! There are many
query processor bugs that have been fixed since the product was released.
Thanks for the CREATE TABLE, but once you've done that, you're going to have
to provide us with enough sample data to reproduce your problem (as well as
tell us which rows you were expecting in the result set!). Otherwise, it's
impossible for us to determine exactly what's happening, why it doesn't meet
your criteria, and test our suggestions on fixing it...
See http://www.aspfaq.com/5006
http://www.aspfaq.com/
(Reverse address to reply.)|||Allan,
After you install service pack 3a as Aaron suggested, I suggest you
consider two other things:
* Rwrite the query using ANSI outer join syntax (... left outer join on
...), which, unlike *=, is always unambiguous
* Consider a different data type than FLOAT for data that must be
compared with the = operator. Because FLOAT values are approximate, you
cannot count on tests of equality to be reliable.
Steve Kass
Drew University
Allan Kelly wrote:

>I have a problem with a query. When I omit the TOP clause I get more
>rows returned than I expect (12 rows out of a 119 in the table), but
>when I include TOP I get 5 rows from the same data with the otherwise
>unchanged table.
>Thing is, the query where I include TOP 1000 is the correct result.
>I'm on SQL Server 2000, select @.@.version -
>"Microsoft SQL Server 2000 - 8.00.194 (Intel X86) Aug 6 2000
>00:57:48 Copyright (c) 1988-2000 Microsoft Corporation Developer
>Edition on Windows NT 5.1 (Build 2600: Service Pack 1) "
>I've cut the query down quite a bit, the table
>create table Test (
> CDMA_PDSN63 FLOAT,
> AVE__CORE_46_Count INTEGER,
> AVE__CORE_46_Sum FLOAT);
>The query is
>SELECT * FROM (
>SELECT
>-- TOP 1000 -- comment this in to get correct results
>D.CDMA_PDSN63, NM.AVE__CORE_46x AVE__CORE_46
>FROM (SELECT DISTINCT CDMA_PDSN63
> FROM(SELECT CDMA_PDSN63 FROM Test ) AS dims
> ) AS D,
> (SELECT CDMA_PDSN63,
> CASE when (Sum( AVE__CORE_46_Count))=0 then NULL else
>SUM(AVE__CORE_46_Sum) / SUM( AVE__CORE_46_Count) end AS AVE__CORE_46x
> FROM Test GROUP BY CDMA_PDSN63) AS NM
>WHERE D.CDMA_PDSN63*=NM.CDMA_PDSN63
> ) as MainQuery
>WHERE ROUND(MainQuery.AVE__CORE_46,0) >= 120
>--AND MainQuery.AVE__CORE_46 IS NOT NULL - Note 1
>--ORDER BY CDMA_PDSN63 - Note 2
>Note 1: I tried adding this but it makes not difference
>Note 2: this was in the original query, it makes sense to have it but
>again it makes no difference, I've used in on the inner and outer
>select, no change
>I've also tried TOP 1000 in the outer select again no difference.
>Changing the outer join to a regular join fixes the problem, but I
>need the outer join in the original query. (In the original query
>there are many more sub-selects and several more outer join clauses to
>put them back together.)
>If I use small values for TOP n (e.g. 1, 2, ... < 10) the results are
>even stranger, I get a subset of the expected rows, and not the same
>number as n.
>I tried setting a rowcount as well, no difference.
>I've seen several other queries on this newsgroup which talk about
>similar problems but the threads have never been concluded with a
>clear answer.
>Any ideas? Thanks
>allan
>|||Steve Kass <skass@.drew.edu> wrote in message news:<#Tj3pA0dEHA.1604@.TK2MSFTNGP11.phx.gbl>...

> Allan,
> After you install service pack 3a as Aaron suggested, I suggest you
> consider two other things:
> * Rwrite the query using ANSI outer join syntax (... left outer join on
> ...), which, unlike *=, is always unambiguous
> * Consider a different data type than FLOAT for data that must be
> compared with the = operator. Because FLOAT values are approximate, you
> cannot count on tests of equality to be reliable.
>
Thanks Aaron, Steve,
I rewrote the SQL using ANSI outer join syntax and that fixes the
problem. Great!
Thanks for the reminder to look into the service pack, my code need to
run against MSDE in the final product so I need to check out the
service pack situation there.
allan

Incorrect results if no TOP clause

I have a problem with a query. When I omit the TOP clause I get more
rows returned than I expect (12 rows out of a 119 in the table), but
when I include TOP I get 5 rows from the same data with the otherwise
unchanged table.
Thing is, the query where I include TOP 1000 is the correct result.
I'm on SQL Server 2000, select @.@.version -
"Microsoft SQL Server 2000 - 8.00.194 (Intel X86) Aug 6 2000
00:57:48 Copyright (c) 1988-2000 Microsoft Corporation Developer
Edition on Windows NT 5.1 (Build 2600: Service Pack 1) "
I've cut the query down quite a bit, the table
create table Test (
CDMA_PDSN63 FLOAT,
AVE__CORE_46_Count INTEGER,
AVE__CORE_46_Sum FLOAT);
The query is
SELECT * FROM (
SELECT
-- TOP 1000 -- comment this in to get correct results
D.CDMA_PDSN63, NM.AVE__CORE_46x AVE__CORE_46
FROM (SELECT DISTINCT CDMA_PDSN63
FROM(SELECT CDMA_PDSN63 FROM Test ) AS dims
) AS D,
(SELECT CDMA_PDSN63,
CASE when (Sum( AVE__CORE_46_Count))=0 then NULL else
SUM(AVE__CORE_46_Sum) / SUM( AVE__CORE_46_Count) end AS AVE__CORE_46x
FROM Test GROUP BY CDMA_PDSN63) AS NM
WHERE D.CDMA_PDSN63*=NM.CDMA_PDSN63
) as MainQuery
WHERE ROUND(MainQuery.AVE__CORE_46,0) >= 120
--AND MainQuery.AVE__CORE_46 IS NOT NULL - Note 1
--ORDER BY CDMA_PDSN63 - Note 2
Note 1: I tried adding this but it makes not difference
Note 2: this was in the original query, it makes sense to have it but
again it makes no difference, I've used in on the inner and outer
select, no change
I've also tried TOP 1000 in the outer select again no difference.
Changing the outer join to a regular join fixes the problem, but I
need the outer join in the original query. (In the original query
there are many more sub-selects and several more outer join clauses to
put them back together.)
If I use small values for TOP n (e.g. 1, 2, ... < 10) the results are
even stranger, I get a subset of the expected rows, and not the same
number as n.
I tried setting a rowcount as well, no difference.
I've seen several other queries on this newsgroup which talk about
similar problems but the threads have never been concluded with a
clear answer.
Any ideas? Thanks
allan> "Microsoft SQL Server 2000 - 8.00.194
You're on RTM! Install Service Pack 3a, right away, please! There are many
query processor bugs that have been fixed since the product was released.
Thanks for the CREATE TABLE, but once you've done that, you're going to have
to provide us with enough sample data to reproduce your problem (as well as
tell us which rows you were expecting in the result set!). Otherwise, it's
impossible for us to determine exactly what's happening, why it doesn't meet
your criteria, and test our suggestions on fixing it...
See http://www.aspfaq.com/5006
--
http://www.aspfaq.com/
(Reverse address to reply.)|||Allan,
After you install service pack 3a as Aaron suggested, I suggest you
consider two other things:
* Rwrite the query using ANSI outer join syntax (... left outer join on
...), which, unlike *=, is always unambiguous
* Consider a different data type than FLOAT for data that must be
compared with the = operator. Because FLOAT values are approximate, you
cannot count on tests of equality to be reliable.
Steve Kass
Drew University
Allan Kelly wrote:
>I have a problem with a query. When I omit the TOP clause I get more
>rows returned than I expect (12 rows out of a 119 in the table), but
>when I include TOP I get 5 rows from the same data with the otherwise
>unchanged table.
>Thing is, the query where I include TOP 1000 is the correct result.
>I'm on SQL Server 2000, select @.@.version -
>"Microsoft SQL Server 2000 - 8.00.194 (Intel X86) Aug 6 2000
>00:57:48 Copyright (c) 1988-2000 Microsoft Corporation Developer
>Edition on Windows NT 5.1 (Build 2600: Service Pack 1) "
>I've cut the query down quite a bit, the table
>create table Test (
> CDMA_PDSN63 FLOAT,
> AVE__CORE_46_Count INTEGER,
> AVE__CORE_46_Sum FLOAT);
>The query is
>SELECT * FROM (
>SELECT
>-- TOP 1000 -- comment this in to get correct results
>D.CDMA_PDSN63, NM.AVE__CORE_46x AVE__CORE_46
>FROM (SELECT DISTINCT CDMA_PDSN63
> FROM(SELECT CDMA_PDSN63 FROM Test ) AS dims
>) AS D,
> (SELECT CDMA_PDSN63,
> CASE when (Sum( AVE__CORE_46_Count))=0 then NULL else
>SUM(AVE__CORE_46_Sum) / SUM( AVE__CORE_46_Count) end AS AVE__CORE_46x
> FROM Test GROUP BY CDMA_PDSN63) AS NM
>WHERE D.CDMA_PDSN63*=NM.CDMA_PDSN63
>) as MainQuery
>WHERE ROUND(MainQuery.AVE__CORE_46,0) >= 120
>--AND MainQuery.AVE__CORE_46 IS NOT NULL - Note 1
>--ORDER BY CDMA_PDSN63 - Note 2
>Note 1: I tried adding this but it makes not difference
>Note 2: this was in the original query, it makes sense to have it but
>again it makes no difference, I've used in on the inner and outer
>select, no change
>I've also tried TOP 1000 in the outer select again no difference.
>Changing the outer join to a regular join fixes the problem, but I
>need the outer join in the original query. (In the original query
>there are many more sub-selects and several more outer join clauses to
>put them back together.)
>If I use small values for TOP n (e.g. 1, 2, ... < 10) the results are
>even stranger, I get a subset of the expected rows, and not the same
>number as n.
>I tried setting a rowcount as well, no difference.
>I've seen several other queries on this newsgroup which talk about
>similar problems but the threads have never been concluded with a
>clear answer.
>Any ideas? Thanks
>allan
>|||Steve Kass <skass@.drew.edu> wrote in message news:<#Tj3pA0dEHA.1604@.TK2MSFTNGP11.phx.gbl>...
> Allan,
> After you install service pack 3a as Aaron suggested, I suggest you
> consider two other things:
> * Rwrite the query using ANSI outer join syntax (... left outer join on
> ...), which, unlike *=, is always unambiguous
> * Consider a different data type than FLOAT for data that must be
> compared with the = operator. Because FLOAT values are approximate, you
> cannot count on tests of equality to be reliable.
>
Thanks Aaron, Steve,
I rewrote the SQL using ANSI outer join syntax and that fixes the
problem. Great!
Thanks for the reminder to look into the service pack, my code need to
run against MSDE in the final product so I need to check out the
service pack situation there.
allansql

Monday, March 19, 2012

Incorrect columns returned by view

When I create a view consisting of an inner join between a view and a
table the columns refernced in the the view are returned incorrectly,
example

select id.itemcode, id.description, iv.linevalue, iv.vatvalue from
dbo.tbl_itemdetails id inner join dbo.vw_invoices iv where
dbo.tbl_itemdetails.itemcode = dbo.vw_invoices.itemcode

The actual value that is returned from the view is the column
immediately to the left of the linevalue column, ie stockroomThe code you have posted isn't correct syntax, you've missed the ON clause.

One possibility for you: Could it be that you have some control characters
such as carriage return/line feed in one of the columns you are returning?
Special characters sometimes cause formatting problems when displaying data
in Query Analyzer.

If you need more help please post some code we can run that will reproduce
the problem: DDL (CREATE TABLE statement(s) for the table(s)), sample data
(INSERT statements) and the actual definition of the view.

--
David Portas
SQL Server MVP
--|||Yeah it was just a quick rehash of the view, limiting the information
for demo purposes the actual view(vw_test) is below:

CREATE VIEW dbo.vw_test
AS
SELECT dbo.vw_Invoices_I.ID_Company_Number,
dbo.vw_Invoices_I.ID_Item_Code, dbo.vw_Invoices_I.I_Order_Number,
dbo.vw_Invoices_I.I_Order_Line_Number,
dbo.vw_Invoices_I.I_Invoice_Number, dbo.vw_Invoices_I.I_Customer_Number,
dbo.vw_Invoices_I.I_Delivery_Address_Code,
dbo.vw_Invoices_I.I_Line_Value *
dbo.tbl_Lagged_Sales.Percentage_Of_Sales AS Expr1,
dbo.vw_Invoices_I.I_VAT_Value,
dbo.vw_Invoices_I.I_Discount_Value, dbo.vw_Invoices_I.I_Standard_Cost,
dbo.vw_Invoices_I.I_Line_Cost_Value
FROM dbo.tbl_Lagged_Sales INNER JOIN
dbo.vw_Invoices_I ON
dbo.tbl_Lagged_Sales.Supplier_Code = dbo.vw_Invoices_I.ID_Company AND
dbo.tbl_Lagged_Sales.Lag_Product_Group =
dbo.vw_Invoices_I.ID_Product_GroupHi

if exists (select * from dbo.sysobjects where id =
object_id(N'[dbo].[tbl_Invoices_I_DB_TEST]') and OBJECTPROPERTY(id,
N'IsUserTable') = 1)
drop table [dbo].[tbl_Invoices_I_DB_TEST]
GO

CREATE TABLE [dbo].[tbl_Invoices_I_DB_TEST] (
[I_Company_Number] [char] (2) COLLATE Latin1_General_CI_AS NOT NULL ,
[I_Order_Number] [char] (7) COLLATE Latin1_General_CI_AS NOT NULL ,
[I_Order_Line_Number] [smallint] NOT NULL ,
[I_Invoice_Number] [char] (7) COLLATE Latin1_General_CI_AS NOT NULL ,
[I_Disp_Seq_No] [char] (3) COLLATE Latin1_General_CI_AS NOT NULL ,
[I_Item_Code] [char] (15) COLLATE Latin1_General_CI_AS NULL ,
[I_Pack_Item_Code] [char] (15) COLLATE Latin1_General_CI_AS NULL ,
[I_Stockroom] [char] (2) COLLATE Latin1_General_CI_AS NULL ,
[I_Line_Value] [numeric](17, 2) NOT NULL ,
[I_VAT_Value] [numeric](17, 2) NULL ,
[I_Discount_Value] [numeric](17, 2) NULL ,
[I_Standard_Cost] [numeric](17, 2) NULL ,
[I_Line_Quantity] [numeric](13, 3) NOT NULL ,
[I_Week_Number] [int] NULL ,
[I_Period_Number] [int] NULL ,
[I_Transaction_Type] [smallint] NULL ,
[I_Transaction_Date] [int] NULL ,
[I_Customer_Number] [char] (8) COLLATE Latin1_General_CI_AS NULL ,
[I_Delivery_Address_Code] [char] (3) COLLATE Latin1_General_CI_AS NULL
,
[I_Line_Cost_Value] [numeric](17, 2) NOT NULL ,
[I_Status] [char] (1) COLLATE Latin1_General_CI_AS NULL ,
[I_Parent_Line_Number] [smallint] NULL ,
[I_Reason_Code] [char] (1) COLLATE Latin1_General_CI_AS NULL ,
[I_Print_Flag] [char] (1) COLLATE Latin1_General_CI_AS NULL ,
[I_Sales_Analysis_Update_Flag] [char] (1) COLLATE Latin1_General_CI_AS
NULL ,
[I_Item_Type] [char] (1) COLLATE Latin1_General_CI_AS NULL ,
[I_Sales_Type] [int] NULL ,
[I_Month_Number] [tinyint] NOT NULL ,
[I_Year_Number] [smallint] NOT NULL ,
[I_Transaction_Date_PC] [datetime] NOT NULL ,
[I_Gross_Margin] [numeric](17, 2) NULL ,
[I_Date_Downloaded] [datetime] NULL ,
[Flagged_for_Exception] [bit] NULL
) ON [PRIMARY]
GO

CREATE VIEW dbo.vw_Invoices_I
AS
SELECT dbo.vw_Item_Details_ID.*, dbo.tbl_Invoices_I_DB_TEST.*,
dbo.vw_Customer_Details.*
FROM dbo.tbl_Invoices_I_DB_TEST INNER JOIN
dbo.vw_Customer_Details ON
dbo.tbl_Invoices_I_DB_TEST.I_Company_Number =
dbo.vw_Customer_Details.CD_Company_Number AND
dbo.tbl_Invoices_I_DB_TEST.I_Customer_Number =
dbo.vw_Customer_Details.CD_Customer_Number AND
dbo.tbl_Invoices_I_DB_TEST.I_Delivery_Address_Code
= dbo.vw_Customer_Details.CD_Dseq INNER JOIN
dbo.vw_Item_Details_ID ON
dbo.tbl_Invoices_I_DB_TEST.I_Company_Number =
dbo.vw_Item_Details_ID.ID_Company_Number AND
dbo.tbl_Invoices_I_DB_TEST.I_Item_Code =
dbo.vw_Item_Details_ID.ID_Item_Code

CREATE VIEW dbo.vw_Item_Details_ID
AS
SELECT dbo.tbl_Item_Details_ID.ID_Company_Number,
dbo.tbl_Item_Details_ID.ID_Item_Code,
dbo.tbl_Item_Details_ID.ID_Description,
dbo.tbl_Item_Details_ID.ID_STD_Cost,
dbo.tbl_Item_Details_ID.ID_Product_Type,
dbo.tbl_ILU_Z_PTYP.Z_Product_Type_Description,
dbo.tbl_Item_Details_ID.ID_Company,
dbo.tbl_ILU_A_COMP.A_Company_Description,
dbo.tbl_Item_Details_ID.ID_Brand_Type,
dbo.tbl_ILU_B_BTYP.B_Brand_Type_Description,
dbo.tbl_Item_Details_ID.ID_Brand,
dbo.tbl_ILU_C_BRND.C_Brand_Description,
dbo.tbl_Item_Details_ID.ID_Range,
dbo.tbl_ILU_D_RANG.D_Range_Description, dbo.tbl_Item_Details_ID.ID_Item,
dbo.tbl_ILU_E_ITEM.E_Item_Description,
dbo.tbl_Item_Details_ID.ID_Function_Description,
dbo.tbl_ILU_F_DESC.F_Description_Description,
dbo.tbl_Item_Details_ID.ID_Det_Fuel,
dbo.tbl_ILU_G_DET_FUEL.G_Det_Fuel_Description,
dbo.tbl_Item_Details_ID.ID_Colour,
dbo.tbl_ILU_H_COLR.H_Colour_Description,
dbo.tbl_Item_Details_ID.ID_TypeCat,
dbo.tbl_ILU_I_TYPECAT.I_TypeCat_Description,
dbo.tbl_Item_Details_ID.ID_DetFunc,
dbo.tbl_ILU_J_DETFUNC.J_DETFUNC_Description,
dbo.tbl_Item_Details_ID.ID_Function,
dbo.tbl_ILU_K_FCTN.K_Function_Description,
dbo.tbl_Item_Details_ID.ID_Owner,
dbo.tbl_ILU_L_OWNR.L_Owner_Description,
dbo.tbl_Item_Details_ID.ID_Application,
dbo.tbl_ILU_M_APPL.M_Application_Description,
dbo.tbl_Item_Details_ID.ID_Planning_Group,
dbo.tbl_ILU_O_PLANG.O_Planning_Group_Description,
dbo.tbl_Item_Details_ID.ID_Planning_Sub_Group,

dbo.tbl_ILU_P_PLNSG.P_Planning_Sub_Group_Descripti on,
dbo.tbl_Item_Details_ID.ID_Product_Group,
dbo.tbl_ILU_O_GROP.O_PoductGroup_Description,
dbo.tbl_Item_Details_ID.ID_Top_Fuel,
dbo.tbl_ILU_N_TFUL.N_TopFuel_Description,
dbo.tbl_Item_Details_ID.ID_Date_Last_Manufactured,
dbo.tbl_Item_Details_ID.ID_Model, dbo.tbl_ILU_P_MODL.P_Model_Description
FROM dbo.tbl_Item_Details_ID INNER JOIN
dbo.tbl_ILU_P_MODL ON
dbo.tbl_Item_Details_ID.ID_Model = dbo.tbl_ILU_P_MODL.P_MODL_ID LEFT
OUTER JOIN
dbo.tbl_ILU_A_COMP ON
dbo.tbl_Item_Details_ID.ID_Company = dbo.tbl_ILU_A_COMP.A_COMP_ID LEFT
OUTER JOIN
dbo.tbl_ILU_I_TYPECAT ON
dbo.tbl_Item_Details_ID.ID_TypeCat = dbo.tbl_ILU_I_TYPECAT.I_TYPECAT_ID
LEFT OUTER JOIN
dbo.tbl_ILU_E_ITEM ON
dbo.tbl_Item_Details_ID.ID_Item = dbo.tbl_ILU_E_ITEM.E_ITEM_ID LEFT
OUTER JOIN
dbo.tbl_ILU_G_DET_FUEL ON
dbo.tbl_Item_Details_ID.ID_Det_Fuel =
dbo.tbl_ILU_G_DET_FUEL.G_DET_FUEL_ID LEFT OUTER JOIN
dbo.tbl_ILU_J_DETFUNC ON
dbo.tbl_Item_Details_ID.ID_DetFunc = dbo.tbl_ILU_J_DETFUNC.J_DETFUNC_ID
LEFT OUTER JOIN
dbo.tbl_ILU_N_TFUL ON
dbo.tbl_Item_Details_ID.ID_Top_Fuel = dbo.tbl_ILU_N_TFUL.N_TFUL_ID LEFT
OUTER JOIN
dbo.tbl_ILU_O_GROP ON
dbo.tbl_Item_Details_ID.ID_Product_Group = dbo.tbl_ILU_O_GROP.O_GROP_ID
LEFT OUTER JOIN
dbo.tbl_ILU_C_BRND ON
dbo.tbl_Item_Details_ID.ID_Brand = dbo.tbl_ILU_C_BRND.C_BRND_ID LEFT
OUTER JOIN
dbo.tbl_ILU_K_FCTN ON
dbo.tbl_Item_Details_ID.ID_Function = dbo.tbl_ILU_K_FCTN.K_FCTN_ID LEFT
OUTER JOIN
dbo.tbl_ILU_M_APPL ON
dbo.tbl_Item_Details_ID.ID_Application = dbo.tbl_ILU_M_APPL.M_APPL_ID
LEFT OUTER JOIN
dbo.tbl_ILU_P_PLNSG ON
dbo.tbl_Item_Details_ID.ID_Planning_Sub_Group =
dbo.tbl_ILU_P_PLNSG.P_PLNSG_ID LEFT OUTER JOIN
dbo.tbl_ILU_O_PLANG ON
dbo.tbl_Item_Details_ID.ID_Planning_Group =
dbo.tbl_ILU_O_PLANG.O_PLANG_ID LEFT OUTER JOIN
dbo.tbl_ILU_L_OWNR ON
dbo.tbl_Item_Details_ID.ID_Owner = dbo.tbl_ILU_L_OWNR.L_OWNR_ID LEFT
OUTER JOIN
dbo.tbl_ILU_H_COLR ON
dbo.tbl_Item_Details_ID.ID_Colour = dbo.tbl_ILU_H_COLR.H_COLR_ID LEFT
OUTER JOIN
dbo.tbl_ILU_F_DESC ON
dbo.tbl_Item_Details_ID.ID_Function_Description =
dbo.tbl_ILU_F_DESC.F_DESC_ID LEFT OUTER JOIN
dbo.tbl_ILU_D_RANG ON
dbo.tbl_Item_Details_ID.ID_Range = dbo.tbl_ILU_D_RANG.D_RANG_ID LEFT
OUTER JOIN
dbo.tbl_ILU_B_BTYP ON
dbo.tbl_Item_Details_ID.ID_Brand_Type = dbo.tbl_ILU_B_BTYP.B_BTYP_ID
LEFT OUTER JOIN
dbo.tbl_ILU_Z_PTYP ON
dbo.tbl_Item_Details_ID.ID_Product_Type = dbo.tbl_ILU_Z_PTYP.Z_PTYP_ID

CREATE VIEW dbo.vw_Customer_Details
AS
SELECT dbo.tbl_Customer_Details_CD.CD_Company_Number,
dbo.tbl_Customer_Details_CD.CD_Customer_Number,
dbo.tbl_Customer_Details_CD.CD_Dseq,
dbo.tbl_Customer_Details_CD.CD_Customer_Name,
dbo.tbl_Customer_Details_CD.CD_Customer_Address_1,
dbo.tbl_Customer_Details_CD.CD_Customer_Address_2,
dbo.tbl_Customer_Details_CD.CD_Customer_Address_3,
dbo.tbl_Customer_Details_CD.CD_Customer_Address_4,
dbo.tbl_Customer_Details_CD.CD_Customer_Address_5,
dbo.tbl_Customer_Details_CD.CD_Post_Code_1,
dbo.tbl_Customer_Details_CD.CD_Post_Code_2,
dbo.tbl_Customer_Details_CD.CD_Customer_Group_1,
dbo.tbl_Customer_Details_CD.CD_Customer_Group_2,
dbo.tbl_Customer_Details_CD.CD_Customer_Group_3,
dbo.tbl_Customer_Details_CD.CD_Customer_Group_4,
dbo.tbl_Customer_Details_CD.CD_Region,
dbo.tbl_Customer_Details_CD.CD_Credit_Limit,
dbo.tbl_Customer_Details_CD.CD_Customer_Contact,
dbo.tbl_Customer_Details_CD.CD_Phone_Number,
dbo.tbl_Customer_Details_CD.CD_Date_Account_Opened ,

dbo.tbl_Customer_Details_CD.CD_Bank_Account_Number ,
dbo.tbl_Customer_Details_CD.CD_Bank_Account_Name,
dbo.tbl_Customer_Details_CD.CD_Bank_Address_1,
dbo.tbl_Customer_Details_CD.CD_Bank_Address_2,
dbo.tbl_Customer_Details_CD.CD_Credit_Controller,
dbo.tbl_Credit_Controller.CC_Description,
dbo.tbl_Customer_Details_CD.CD_Customer_Group,

dbo.tbl_CLU_Z_CGT.Z_Customer_Group_Type_Descriptio n,
dbo.tbl_Customer_Details_CD.CD_Customer_Parent,

dbo.tbl_CLU_Y_CPT.Y_Customer_Parent_Type_Descripti on,
dbo.tbl_Customer_Details_CD.CD_Sales_Region,
dbo.tbl_CLU_A_SRGN.A_Sales_Region_Description,
dbo.tbl_Customer_Details_CD.CD_Business_Type,
dbo.tbl_CLU_B_BTYP.B_Business_Type_Description,
dbo.tbl_Customer_Details_CD.CD_Distribution_Channe l,

dbo.tbl_CLU_C_DCNL.C_Distribution_Channel_Descript ion,
dbo.tbl_Customer_Details_CD.CD_Distribution_Cluste r,

dbo.tbl_CLU_D_DCSR.D_Distribution_Cluster_Descript ion,
dbo.tbl_Customer_Details_CD.CD_Delivery_Type,
dbo.tbl_CLU_E_DTYP.E_Delivery_Type_Description,
dbo.tbl_Customer_Details_CD.CD_Marketing_Director,

dbo.tbl_CLU_F_MDR.F_Marketing_Director_Resposibili ty_Description,
dbo.tbl_Customer_Details_CD.CD_Sales_Director,

dbo.tbl_CLU_G_SDR.G_Sales_Director_Responsibility_ Description,
dbo.tbl_Customer_Details_CD.CD_Account_Manager,

dbo.tbl_CLU_H_AMR.H_Account_Manager_Responsibility _Description,
dbo.tbl_Customer_Details_CD.CD_Date_Account_Opened _PC,

dbo.tbl_Customer_Details_CD.CD_Consolidated_Custom er,
dbo.tbl_CLU_I_CNSL.I_Consolidated_Customer_Descrip tion
FROM dbo.tbl_Customer_Details_CD LEFT OUTER JOIN
dbo.tbl_CLU_I_CNSL ON
dbo.tbl_Customer_Details_CD.CD_Consolidated_Custom er =
dbo.tbl_CLU_I_CNSL.I_CNSL_ID LEFT OUTER JOIN
dbo.tbl_Credit_Controller ON
dbo.tbl_Customer_Details_CD.CD_Credit_Controller =
dbo.tbl_Credit_Controller.CC_ID LEFT OUTER JOIN
dbo.tbl_CLU_H_AMR ON
dbo.tbl_Customer_Details_CD.CD_Account_Manager =
dbo.tbl_CLU_H_AMR.H_AMR_ID LEFT OUTER JOIN
dbo.tbl_CLU_G_SDR ON
dbo.tbl_Customer_Details_CD.CD_Sales_Director =
dbo.tbl_CLU_G_SDR.G_SDR_ID LEFT OUTER JOIN
dbo.tbl_CLU_F_MDR ON
dbo.tbl_Customer_Details_CD.CD_Marketing_Director =
dbo.tbl_CLU_F_MDR.F_MDR_ID LEFT OUTER JOIN
dbo.tbl_CLU_E_DTYP ON
dbo.tbl_Customer_Details_CD.CD_Delivery_Type =
dbo.tbl_CLU_E_DTYP.E_DTYP_ID LEFT OUTER JOIN
dbo.tbl_CLU_D_DCSR ON
dbo.tbl_Customer_Details_CD.CD_Distribution_Cluste r =
dbo.tbl_CLU_D_DCSR.D_DCSR_ID LEFT OUTER JOIN
dbo.tbl_CLU_C_DCNL ON
dbo.tbl_Customer_Details_CD.CD_Distribution_Channe l =
dbo.tbl_CLU_C_DCNL.C_DCNL_ID LEFT OUTER JOIN
dbo.tbl_CLU_B_BTYP ON
dbo.tbl_Customer_Details_CD.CD_Business_Type =
dbo.tbl_CLU_B_BTYP.B_BTYP_ID LEFT OUTER JOIN
dbo.tbl_CLU_A_SRGN ON
dbo.tbl_Customer_Details_CD.CD_Sales_Region =
dbo.tbl_CLU_A_SRGN.A_SRGN_ID LEFT OUTER JOIN
dbo.tbl_CLU_Y_CPT ON
dbo.tbl_Customer_Details_CD.CD_Customer_Parent =
dbo.tbl_CLU_Y_CPT.Y_CPT_ID LEFT OUTER JOIN
dbo.tbl_CLU_Z_CGT ON
dbo.tbl_Customer_Details_CD.CD_Customer_Group =
dbo.tbl_CLU_Z_CGT.Z_CGT_ID

The above should give you some idea of the data, I haven't include the
scripts for the base tables as this would take considerable time

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!|||Hi

It is better not to specify * in the view definition especially in
production code. If you insist on doing it I would recomend using the WITH
SCHEMABINDING attribute. You will probably find that dbo.vw_Invoices_I is
not returning the correct data as you have changed the underlying tables.

Look at sp_refreshview in Books online
mk:@.MSITStore:C:\Program%20Files\Microsoft%20SQL%2 0Server\80\Tools\Books\tsq
lref.chm::/ts_sp_ra-rz_7qnr.htm

John

"John Dennison" <john.dennison@.glendimplex.com> wrote in message
news:407fb2aa$0$204$75868355@.news.frii.net...
> Yeah it was just a quick rehash of the view, limiting the information
> for demo purposes the actual view(vw_test) is below:
> CREATE VIEW dbo.vw_test
> AS
> SELECT dbo.vw_Invoices_I.ID_Company_Number,
> dbo.vw_Invoices_I.ID_Item_Code, dbo.vw_Invoices_I.I_Order_Number,
> dbo.vw_Invoices_I.I_Order_Line_Number,
> dbo.vw_Invoices_I.I_Invoice_Number, dbo.vw_Invoices_I.I_Customer_Number,
> dbo.vw_Invoices_I.I_Delivery_Address_Code,
> dbo.vw_Invoices_I.I_Line_Value *
> dbo.tbl_Lagged_Sales.Percentage_Of_Sales AS Expr1,
> dbo.vw_Invoices_I.I_VAT_Value,
> dbo.vw_Invoices_I.I_Discount_Value, dbo.vw_Invoices_I.I_Standard_Cost,
> dbo.vw_Invoices_I.I_Line_Cost_Value
> FROM dbo.tbl_Lagged_Sales INNER JOIN
> dbo.vw_Invoices_I ON
> dbo.tbl_Lagged_Sales.Supplier_Code = dbo.vw_Invoices_I.ID_Company AND
> dbo.tbl_Lagged_Sales.Lag_Product_Group =
> dbo.vw_Invoices_I.ID_Product_GroupHi
>
> if exists (select * from dbo.sysobjects where id =
> object_id(N'[dbo].[tbl_Invoices_I_DB_TEST]') and OBJECTPROPERTY(id,
> N'IsUserTable') = 1)
> drop table [dbo].[tbl_Invoices_I_DB_TEST]
> GO
> CREATE TABLE [dbo].[tbl_Invoices_I_DB_TEST] (
> [I_Company_Number] [char] (2) COLLATE Latin1_General_CI_AS NOT NULL ,
> [I_Order_Number] [char] (7) COLLATE Latin1_General_CI_AS NOT NULL ,
> [I_Order_Line_Number] [smallint] NOT NULL ,
> [I_Invoice_Number] [char] (7) COLLATE Latin1_General_CI_AS NOT NULL ,
> [I_Disp_Seq_No] [char] (3) COLLATE Latin1_General_CI_AS NOT NULL ,
> [I_Item_Code] [char] (15) COLLATE Latin1_General_CI_AS NULL ,
> [I_Pack_Item_Code] [char] (15) COLLATE Latin1_General_CI_AS NULL ,
> [I_Stockroom] [char] (2) COLLATE Latin1_General_CI_AS NULL ,
> [I_Line_Value] [numeric](17, 2) NOT NULL ,
> [I_VAT_Value] [numeric](17, 2) NULL ,
> [I_Discount_Value] [numeric](17, 2) NULL ,
> [I_Standard_Cost] [numeric](17, 2) NULL ,
> [I_Line_Quantity] [numeric](13, 3) NOT NULL ,
> [I_Week_Number] [int] NULL ,
> [I_Period_Number] [int] NULL ,
> [I_Transaction_Type] [smallint] NULL ,
> [I_Transaction_Date] [int] NULL ,
> [I_Customer_Number] [char] (8) COLLATE Latin1_General_CI_AS NULL ,
> [I_Delivery_Address_Code] [char] (3) COLLATE Latin1_General_CI_AS NULL
> ,
> [I_Line_Cost_Value] [numeric](17, 2) NOT NULL ,
> [I_Status] [char] (1) COLLATE Latin1_General_CI_AS NULL ,
> [I_Parent_Line_Number] [smallint] NULL ,
> [I_Reason_Code] [char] (1) COLLATE Latin1_General_CI_AS NULL ,
> [I_Print_Flag] [char] (1) COLLATE Latin1_General_CI_AS NULL ,
> [I_Sales_Analysis_Update_Flag] [char] (1) COLLATE Latin1_General_CI_AS
> NULL ,
> [I_Item_Type] [char] (1) COLLATE Latin1_General_CI_AS NULL ,
> [I_Sales_Type] [int] NULL ,
> [I_Month_Number] [tinyint] NOT NULL ,
> [I_Year_Number] [smallint] NOT NULL ,
> [I_Transaction_Date_PC] [datetime] NOT NULL ,
> [I_Gross_Margin] [numeric](17, 2) NULL ,
> [I_Date_Downloaded] [datetime] NULL ,
> [Flagged_for_Exception] [bit] NULL
> ) ON [PRIMARY]
> GO
>
> CREATE VIEW dbo.vw_Invoices_I
> AS
> SELECT dbo.vw_Item_Details_ID.*, dbo.tbl_Invoices_I_DB_TEST.*,
> dbo.vw_Customer_Details.*
> FROM dbo.tbl_Invoices_I_DB_TEST INNER JOIN
> dbo.vw_Customer_Details ON
> dbo.tbl_Invoices_I_DB_TEST.I_Company_Number =
> dbo.vw_Customer_Details.CD_Company_Number AND
> dbo.tbl_Invoices_I_DB_TEST.I_Customer_Number =
> dbo.vw_Customer_Details.CD_Customer_Number AND
> dbo.tbl_Invoices_I_DB_TEST.I_Delivery_Address_Code
> = dbo.vw_Customer_Details.CD_Dseq INNER JOIN
> dbo.vw_Item_Details_ID ON
> dbo.tbl_Invoices_I_DB_TEST.I_Company_Number =
> dbo.vw_Item_Details_ID.ID_Company_Number AND
> dbo.tbl_Invoices_I_DB_TEST.I_Item_Code =
> dbo.vw_Item_Details_ID.ID_Item_Code
> CREATE VIEW dbo.vw_Item_Details_ID
> AS
> SELECT dbo.tbl_Item_Details_ID.ID_Company_Number,
> dbo.tbl_Item_Details_ID.ID_Item_Code,
> dbo.tbl_Item_Details_ID.ID_Description,
> dbo.tbl_Item_Details_ID.ID_STD_Cost,
> dbo.tbl_Item_Details_ID.ID_Product_Type,
> dbo.tbl_ILU_Z_PTYP.Z_Product_Type_Description,
> dbo.tbl_Item_Details_ID.ID_Company,
> dbo.tbl_ILU_A_COMP.A_Company_Description,
> dbo.tbl_Item_Details_ID.ID_Brand_Type,
> dbo.tbl_ILU_B_BTYP.B_Brand_Type_Description,
> dbo.tbl_Item_Details_ID.ID_Brand,
> dbo.tbl_ILU_C_BRND.C_Brand_Description,
> dbo.tbl_Item_Details_ID.ID_Range,
> dbo.tbl_ILU_D_RANG.D_Range_Description, dbo.tbl_Item_Details_ID.ID_Item,
> dbo.tbl_ILU_E_ITEM.E_Item_Description,
> dbo.tbl_Item_Details_ID.ID_Function_Description,
> dbo.tbl_ILU_F_DESC.F_Description_Description,
> dbo.tbl_Item_Details_ID.ID_Det_Fuel,
> dbo.tbl_ILU_G_DET_FUEL.G_Det_Fuel_Description,
> dbo.tbl_Item_Details_ID.ID_Colour,
> dbo.tbl_ILU_H_COLR.H_Colour_Description,
> dbo.tbl_Item_Details_ID.ID_TypeCat,
> dbo.tbl_ILU_I_TYPECAT.I_TypeCat_Description,
> dbo.tbl_Item_Details_ID.ID_DetFunc,
> dbo.tbl_ILU_J_DETFUNC.J_DETFUNC_Description,
> dbo.tbl_Item_Details_ID.ID_Function,
> dbo.tbl_ILU_K_FCTN.K_Function_Description,
> dbo.tbl_Item_Details_ID.ID_Owner,
> dbo.tbl_ILU_L_OWNR.L_Owner_Description,
> dbo.tbl_Item_Details_ID.ID_Application,
> dbo.tbl_ILU_M_APPL.M_Application_Description,
> dbo.tbl_Item_Details_ID.ID_Planning_Group,
> dbo.tbl_ILU_O_PLANG.O_Planning_Group_Description,
> dbo.tbl_Item_Details_ID.ID_Planning_Sub_Group,
> dbo.tbl_ILU_P_PLNSG.P_Planning_Sub_Group_Descripti on,
> dbo.tbl_Item_Details_ID.ID_Product_Group,
> dbo.tbl_ILU_O_GROP.O_PoductGroup_Description,
> dbo.tbl_Item_Details_ID.ID_Top_Fuel,
> dbo.tbl_ILU_N_TFUL.N_TopFuel_Description,
> dbo.tbl_Item_Details_ID.ID_Date_Last_Manufactured,
> dbo.tbl_Item_Details_ID.ID_Model, dbo.tbl_ILU_P_MODL.P_Model_Description
> FROM dbo.tbl_Item_Details_ID INNER JOIN
> dbo.tbl_ILU_P_MODL ON
> dbo.tbl_Item_Details_ID.ID_Model = dbo.tbl_ILU_P_MODL.P_MODL_ID LEFT
> OUTER JOIN
> dbo.tbl_ILU_A_COMP ON
> dbo.tbl_Item_Details_ID.ID_Company = dbo.tbl_ILU_A_COMP.A_COMP_ID LEFT
> OUTER JOIN
> dbo.tbl_ILU_I_TYPECAT ON
> dbo.tbl_Item_Details_ID.ID_TypeCat = dbo.tbl_ILU_I_TYPECAT.I_TYPECAT_ID
> LEFT OUTER JOIN
> dbo.tbl_ILU_E_ITEM ON
> dbo.tbl_Item_Details_ID.ID_Item = dbo.tbl_ILU_E_ITEM.E_ITEM_ID LEFT
> OUTER JOIN
> dbo.tbl_ILU_G_DET_FUEL ON
> dbo.tbl_Item_Details_ID.ID_Det_Fuel =
> dbo.tbl_ILU_G_DET_FUEL.G_DET_FUEL_ID LEFT OUTER JOIN
> dbo.tbl_ILU_J_DETFUNC ON
> dbo.tbl_Item_Details_ID.ID_DetFunc = dbo.tbl_ILU_J_DETFUNC.J_DETFUNC_ID
> LEFT OUTER JOIN
> dbo.tbl_ILU_N_TFUL ON
> dbo.tbl_Item_Details_ID.ID_Top_Fuel = dbo.tbl_ILU_N_TFUL.N_TFUL_ID LEFT
> OUTER JOIN
> dbo.tbl_ILU_O_GROP ON
> dbo.tbl_Item_Details_ID.ID_Product_Group = dbo.tbl_ILU_O_GROP.O_GROP_ID
> LEFT OUTER JOIN
> dbo.tbl_ILU_C_BRND ON
> dbo.tbl_Item_Details_ID.ID_Brand = dbo.tbl_ILU_C_BRND.C_BRND_ID LEFT
> OUTER JOIN
> dbo.tbl_ILU_K_FCTN ON
> dbo.tbl_Item_Details_ID.ID_Function = dbo.tbl_ILU_K_FCTN.K_FCTN_ID LEFT
> OUTER JOIN
> dbo.tbl_ILU_M_APPL ON
> dbo.tbl_Item_Details_ID.ID_Application = dbo.tbl_ILU_M_APPL.M_APPL_ID
> LEFT OUTER JOIN
> dbo.tbl_ILU_P_PLNSG ON
> dbo.tbl_Item_Details_ID.ID_Planning_Sub_Group =
> dbo.tbl_ILU_P_PLNSG.P_PLNSG_ID LEFT OUTER JOIN
> dbo.tbl_ILU_O_PLANG ON
> dbo.tbl_Item_Details_ID.ID_Planning_Group =
> dbo.tbl_ILU_O_PLANG.O_PLANG_ID LEFT OUTER JOIN
> dbo.tbl_ILU_L_OWNR ON
> dbo.tbl_Item_Details_ID.ID_Owner = dbo.tbl_ILU_L_OWNR.L_OWNR_ID LEFT
> OUTER JOIN
> dbo.tbl_ILU_H_COLR ON
> dbo.tbl_Item_Details_ID.ID_Colour = dbo.tbl_ILU_H_COLR.H_COLR_ID LEFT
> OUTER JOIN
> dbo.tbl_ILU_F_DESC ON
> dbo.tbl_Item_Details_ID.ID_Function_Description =
> dbo.tbl_ILU_F_DESC.F_DESC_ID LEFT OUTER JOIN
> dbo.tbl_ILU_D_RANG ON
> dbo.tbl_Item_Details_ID.ID_Range = dbo.tbl_ILU_D_RANG.D_RANG_ID LEFT
> OUTER JOIN
> dbo.tbl_ILU_B_BTYP ON
> dbo.tbl_Item_Details_ID.ID_Brand_Type = dbo.tbl_ILU_B_BTYP.B_BTYP_ID
> LEFT OUTER JOIN
> dbo.tbl_ILU_Z_PTYP ON
> dbo.tbl_Item_Details_ID.ID_Product_Type = dbo.tbl_ILU_Z_PTYP.Z_PTYP_ID
> CREATE VIEW dbo.vw_Customer_Details
> AS
> SELECT dbo.tbl_Customer_Details_CD.CD_Company_Number,
> dbo.tbl_Customer_Details_CD.CD_Customer_Number,
> dbo.tbl_Customer_Details_CD.CD_Dseq,
> dbo.tbl_Customer_Details_CD.CD_Customer_Name,
> dbo.tbl_Customer_Details_CD.CD_Customer_Address_1,
> dbo.tbl_Customer_Details_CD.CD_Customer_Address_2,
> dbo.tbl_Customer_Details_CD.CD_Customer_Address_3,
> dbo.tbl_Customer_Details_CD.CD_Customer_Address_4,
> dbo.tbl_Customer_Details_CD.CD_Customer_Address_5,
> dbo.tbl_Customer_Details_CD.CD_Post_Code_1,
> dbo.tbl_Customer_Details_CD.CD_Post_Code_2,
> dbo.tbl_Customer_Details_CD.CD_Customer_Group_1,
> dbo.tbl_Customer_Details_CD.CD_Customer_Group_2,
> dbo.tbl_Customer_Details_CD.CD_Customer_Group_3,
> dbo.tbl_Customer_Details_CD.CD_Customer_Group_4,
> dbo.tbl_Customer_Details_CD.CD_Region,
> dbo.tbl_Customer_Details_CD.CD_Credit_Limit,
> dbo.tbl_Customer_Details_CD.CD_Customer_Contact,
> dbo.tbl_Customer_Details_CD.CD_Phone_Number,
> dbo.tbl_Customer_Details_CD.CD_Date_Account_Opened ,
> dbo.tbl_Customer_Details_CD.CD_Bank_Account_Number ,
> dbo.tbl_Customer_Details_CD.CD_Bank_Account_Name,
> dbo.tbl_Customer_Details_CD.CD_Bank_Address_1,
> dbo.tbl_Customer_Details_CD.CD_Bank_Address_2,
> dbo.tbl_Customer_Details_CD.CD_Credit_Controller,
> dbo.tbl_Credit_Controller.CC_Description,
> dbo.tbl_Customer_Details_CD.CD_Customer_Group,
> dbo.tbl_CLU_Z_CGT.Z_Customer_Group_Type_Descriptio n,
> dbo.tbl_Customer_Details_CD.CD_Customer_Parent,
> dbo.tbl_CLU_Y_CPT.Y_Customer_Parent_Type_Descripti on,
> dbo.tbl_Customer_Details_CD.CD_Sales_Region,
> dbo.tbl_CLU_A_SRGN.A_Sales_Region_Description,
> dbo.tbl_Customer_Details_CD.CD_Business_Type,
> dbo.tbl_CLU_B_BTYP.B_Business_Type_Description,
> dbo.tbl_Customer_Details_CD.CD_Distribution_Channe l,
> dbo.tbl_CLU_C_DCNL.C_Distribution_Channel_Descript ion,
> dbo.tbl_Customer_Details_CD.CD_Distribution_Cluste r,
> dbo.tbl_CLU_D_DCSR.D_Distribution_Cluster_Descript ion,
> dbo.tbl_Customer_Details_CD.CD_Delivery_Type,
> dbo.tbl_CLU_E_DTYP.E_Delivery_Type_Description,
> dbo.tbl_Customer_Details_CD.CD_Marketing_Director,
> dbo.tbl_CLU_F_MDR.F_Marketing_Director_Resposibili ty_Description,
> dbo.tbl_Customer_Details_CD.CD_Sales_Director,
> dbo.tbl_CLU_G_SDR.G_Sales_Director_Responsibility_ Description,
> dbo.tbl_Customer_Details_CD.CD_Account_Manager,
> dbo.tbl_CLU_H_AMR.H_Account_Manager_Responsibility _Description,
> dbo.tbl_Customer_Details_CD.CD_Date_Account_Opened _PC,
> dbo.tbl_Customer_Details_CD.CD_Consolidated_Custom er,
> dbo.tbl_CLU_I_CNSL.I_Consolidated_Customer_Descrip tion
> FROM dbo.tbl_Customer_Details_CD LEFT OUTER JOIN
> dbo.tbl_CLU_I_CNSL ON
> dbo.tbl_Customer_Details_CD.CD_Consolidated_Custom er =
> dbo.tbl_CLU_I_CNSL.I_CNSL_ID LEFT OUTER JOIN
> dbo.tbl_Credit_Controller ON
> dbo.tbl_Customer_Details_CD.CD_Credit_Controller =
> dbo.tbl_Credit_Controller.CC_ID LEFT OUTER JOIN
> dbo.tbl_CLU_H_AMR ON
> dbo.tbl_Customer_Details_CD.CD_Account_Manager =
> dbo.tbl_CLU_H_AMR.H_AMR_ID LEFT OUTER JOIN
> dbo.tbl_CLU_G_SDR ON
> dbo.tbl_Customer_Details_CD.CD_Sales_Director =
> dbo.tbl_CLU_G_SDR.G_SDR_ID LEFT OUTER JOIN
> dbo.tbl_CLU_F_MDR ON
> dbo.tbl_Customer_Details_CD.CD_Marketing_Director =
> dbo.tbl_CLU_F_MDR.F_MDR_ID LEFT OUTER JOIN
> dbo.tbl_CLU_E_DTYP ON
> dbo.tbl_Customer_Details_CD.CD_Delivery_Type =
> dbo.tbl_CLU_E_DTYP.E_DTYP_ID LEFT OUTER JOIN
> dbo.tbl_CLU_D_DCSR ON
> dbo.tbl_Customer_Details_CD.CD_Distribution_Cluste r =
> dbo.tbl_CLU_D_DCSR.D_DCSR_ID LEFT OUTER JOIN
> dbo.tbl_CLU_C_DCNL ON
> dbo.tbl_Customer_Details_CD.CD_Distribution_Channe l =
> dbo.tbl_CLU_C_DCNL.C_DCNL_ID LEFT OUTER JOIN
> dbo.tbl_CLU_B_BTYP ON
> dbo.tbl_Customer_Details_CD.CD_Business_Type =
> dbo.tbl_CLU_B_BTYP.B_BTYP_ID LEFT OUTER JOIN
> dbo.tbl_CLU_A_SRGN ON
> dbo.tbl_Customer_Details_CD.CD_Sales_Region =
> dbo.tbl_CLU_A_SRGN.A_SRGN_ID LEFT OUTER JOIN
> dbo.tbl_CLU_Y_CPT ON
> dbo.tbl_Customer_Details_CD.CD_Customer_Parent =
> dbo.tbl_CLU_Y_CPT.Y_CPT_ID LEFT OUTER JOIN
> dbo.tbl_CLU_Z_CGT ON
> dbo.tbl_Customer_Details_CD.CD_Customer_Group =
> dbo.tbl_CLU_Z_CGT.Z_CGT_ID
>
> The above should give you some idea of the data, I haven't include the
> scripts for the base tables as this would take considerable time
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!|||Hi

It is better not to specify * in the view definition especially in
production code. If you insist on doing it I would recomend using the WITH
SCHEMABINDING attribute. You will probably find that dbo.vw_Invoices_I is
not returning the correct data as you have changed the underlying tables.

Look at sp_refreshview in Books online
mk:@.MSITStore:C:\Program%20Files\Microsoft%20SQL%2 0Server\80\Tools\Books\tsq
lref.chm::/ts_sp_ra-rz_7qnr.htm

John

"John Dennison" <john.dennison@.glendimplex.com> wrote in message
news:407fb2aa$0$204$75868355@.news.frii.net...
> Yeah it was just a quick rehash of the view, limiting the information
> for demo purposes the actual view(vw_test) is below:
> CREATE VIEW dbo.vw_test
> AS
> SELECT dbo.vw_Invoices_I.ID_Company_Number,
> dbo.vw_Invoices_I.ID_Item_Code, dbo.vw_Invoices_I.I_Order_Number,
> dbo.vw_Invoices_I.I_Order_Line_Number,
> dbo.vw_Invoices_I.I_Invoice_Number, dbo.vw_Invoices_I.I_Customer_Number,
> dbo.vw_Invoices_I.I_Delivery_Address_Code,
> dbo.vw_Invoices_I.I_Line_Value *
> dbo.tbl_Lagged_Sales.Percentage_Of_Sales AS Expr1,
> dbo.vw_Invoices_I.I_VAT_Value,
> dbo.vw_Invoices_I.I_Discount_Value, dbo.vw_Invoices_I.I_Standard_Cost,
> dbo.vw_Invoices_I.I_Line_Cost_Value
> FROM dbo.tbl_Lagged_Sales INNER JOIN
> dbo.vw_Invoices_I ON
> dbo.tbl_Lagged_Sales.Supplier_Code = dbo.vw_Invoices_I.ID_Company AND
> dbo.tbl_Lagged_Sales.Lag_Product_Group =
> dbo.vw_Invoices_I.ID_Product_GroupHi
>
> if exists (select * from dbo.sysobjects where id =
> object_id(N'[dbo].[tbl_Invoices_I_DB_TEST]') and OBJECTPROPERTY(id,
> N'IsUserTable') = 1)
> drop table [dbo].[tbl_Invoices_I_DB_TEST]
> GO
> CREATE TABLE [dbo].[tbl_Invoices_I_DB_TEST] (
> [I_Company_Number] [char] (2) COLLATE Latin1_General_CI_AS NOT NULL ,
> [I_Order_Number] [char] (7) COLLATE Latin1_General_CI_AS NOT NULL ,
> [I_Order_Line_Number] [smallint] NOT NULL ,
> [I_Invoice_Number] [char] (7) COLLATE Latin1_General_CI_AS NOT NULL ,
> [I_Disp_Seq_No] [char] (3) COLLATE Latin1_General_CI_AS NOT NULL ,
> [I_Item_Code] [char] (15) COLLATE Latin1_General_CI_AS NULL ,
> [I_Pack_Item_Code] [char] (15) COLLATE Latin1_General_CI_AS NULL ,
> [I_Stockroom] [char] (2) COLLATE Latin1_General_CI_AS NULL ,
> [I_Line_Value] [numeric](17, 2) NOT NULL ,
> [I_VAT_Value] [numeric](17, 2) NULL ,
> [I_Discount_Value] [numeric](17, 2) NULL ,
> [I_Standard_Cost] [numeric](17, 2) NULL ,
> [I_Line_Quantity] [numeric](13, 3) NOT NULL ,
> [I_Week_Number] [int] NULL ,
> [I_Period_Number] [int] NULL ,
> [I_Transaction_Type] [smallint] NULL ,
> [I_Transaction_Date] [int] NULL ,
> [I_Customer_Number] [char] (8) COLLATE Latin1_General_CI_AS NULL ,
> [I_Delivery_Address_Code] [char] (3) COLLATE Latin1_General_CI_AS NULL
> ,
> [I_Line_Cost_Value] [numeric](17, 2) NOT NULL ,
> [I_Status] [char] (1) COLLATE Latin1_General_CI_AS NULL ,
> [I_Parent_Line_Number] [smallint] NULL ,
> [I_Reason_Code] [char] (1) COLLATE Latin1_General_CI_AS NULL ,
> [I_Print_Flag] [char] (1) COLLATE Latin1_General_CI_AS NULL ,
> [I_Sales_Analysis_Update_Flag] [char] (1) COLLATE Latin1_General_CI_AS
> NULL ,
> [I_Item_Type] [char] (1) COLLATE Latin1_General_CI_AS NULL ,
> [I_Sales_Type] [int] NULL ,
> [I_Month_Number] [tinyint] NOT NULL ,
> [I_Year_Number] [smallint] NOT NULL ,
> [I_Transaction_Date_PC] [datetime] NOT NULL ,
> [I_Gross_Margin] [numeric](17, 2) NULL ,
> [I_Date_Downloaded] [datetime] NULL ,
> [Flagged_for_Exception] [bit] NULL
> ) ON [PRIMARY]
> GO
>
> CREATE VIEW dbo.vw_Invoices_I
> AS
> SELECT dbo.vw_Item_Details_ID.*, dbo.tbl_Invoices_I_DB_TEST.*,
> dbo.vw_Customer_Details.*
> FROM dbo.tbl_Invoices_I_DB_TEST INNER JOIN
> dbo.vw_Customer_Details ON
> dbo.tbl_Invoices_I_DB_TEST.I_Company_Number =
> dbo.vw_Customer_Details.CD_Company_Number AND
> dbo.tbl_Invoices_I_DB_TEST.I_Customer_Number =
> dbo.vw_Customer_Details.CD_Customer_Number AND
> dbo.tbl_Invoices_I_DB_TEST.I_Delivery_Address_Code
> = dbo.vw_Customer_Details.CD_Dseq INNER JOIN
> dbo.vw_Item_Details_ID ON
> dbo.tbl_Invoices_I_DB_TEST.I_Company_Number =
> dbo.vw_Item_Details_ID.ID_Company_Number AND
> dbo.tbl_Invoices_I_DB_TEST.I_Item_Code =
> dbo.vw_Item_Details_ID.ID_Item_Code
> CREATE VIEW dbo.vw_Item_Details_ID
> AS
> SELECT dbo.tbl_Item_Details_ID.ID_Company_Number,
> dbo.tbl_Item_Details_ID.ID_Item_Code,
> dbo.tbl_Item_Details_ID.ID_Description,
> dbo.tbl_Item_Details_ID.ID_STD_Cost,
> dbo.tbl_Item_Details_ID.ID_Product_Type,
> dbo.tbl_ILU_Z_PTYP.Z_Product_Type_Description,
> dbo.tbl_Item_Details_ID.ID_Company,
> dbo.tbl_ILU_A_COMP.A_Company_Description,
> dbo.tbl_Item_Details_ID.ID_Brand_Type,
> dbo.tbl_ILU_B_BTYP.B_Brand_Type_Description,
> dbo.tbl_Item_Details_ID.ID_Brand,
> dbo.tbl_ILU_C_BRND.C_Brand_Description,
> dbo.tbl_Item_Details_ID.ID_Range,
> dbo.tbl_ILU_D_RANG.D_Range_Description, dbo.tbl_Item_Details_ID.ID_Item,
> dbo.tbl_ILU_E_ITEM.E_Item_Description,
> dbo.tbl_Item_Details_ID.ID_Function_Description,
> dbo.tbl_ILU_F_DESC.F_Description_Description,
> dbo.tbl_Item_Details_ID.ID_Det_Fuel,
> dbo.tbl_ILU_G_DET_FUEL.G_Det_Fuel_Description,
> dbo.tbl_Item_Details_ID.ID_Colour,
> dbo.tbl_ILU_H_COLR.H_Colour_Description,
> dbo.tbl_Item_Details_ID.ID_TypeCat,
> dbo.tbl_ILU_I_TYPECAT.I_TypeCat_Description,
> dbo.tbl_Item_Details_ID.ID_DetFunc,
> dbo.tbl_ILU_J_DETFUNC.J_DETFUNC_Description,
> dbo.tbl_Item_Details_ID.ID_Function,
> dbo.tbl_ILU_K_FCTN.K_Function_Description,
> dbo.tbl_Item_Details_ID.ID_Owner,
> dbo.tbl_ILU_L_OWNR.L_Owner_Description,
> dbo.tbl_Item_Details_ID.ID_Application,
> dbo.tbl_ILU_M_APPL.M_Application_Description,
> dbo.tbl_Item_Details_ID.ID_Planning_Group,
> dbo.tbl_ILU_O_PLANG.O_Planning_Group_Description,
> dbo.tbl_Item_Details_ID.ID_Planning_Sub_Group,
> dbo.tbl_ILU_P_PLNSG.P_Planning_Sub_Group_Descripti on,
> dbo.tbl_Item_Details_ID.ID_Product_Group,
> dbo.tbl_ILU_O_GROP.O_PoductGroup_Description,
> dbo.tbl_Item_Details_ID.ID_Top_Fuel,
> dbo.tbl_ILU_N_TFUL.N_TopFuel_Description,
> dbo.tbl_Item_Details_ID.ID_Date_Last_Manufactured,
> dbo.tbl_Item_Details_ID.ID_Model, dbo.tbl_ILU_P_MODL.P_Model_Description
> FROM dbo.tbl_Item_Details_ID INNER JOIN
> dbo.tbl_ILU_P_MODL ON
> dbo.tbl_Item_Details_ID.ID_Model = dbo.tbl_ILU_P_MODL.P_MODL_ID LEFT
> OUTER JOIN
> dbo.tbl_ILU_A_COMP ON
> dbo.tbl_Item_Details_ID.ID_Company = dbo.tbl_ILU_A_COMP.A_COMP_ID LEFT
> OUTER JOIN
> dbo.tbl_ILU_I_TYPECAT ON
> dbo.tbl_Item_Details_ID.ID_TypeCat = dbo.tbl_ILU_I_TYPECAT.I_TYPECAT_ID
> LEFT OUTER JOIN
> dbo.tbl_ILU_E_ITEM ON
> dbo.tbl_Item_Details_ID.ID_Item = dbo.tbl_ILU_E_ITEM.E_ITEM_ID LEFT
> OUTER JOIN
> dbo.tbl_ILU_G_DET_FUEL ON
> dbo.tbl_Item_Details_ID.ID_Det_Fuel =
> dbo.tbl_ILU_G_DET_FUEL.G_DET_FUEL_ID LEFT OUTER JOIN
> dbo.tbl_ILU_J_DETFUNC ON
> dbo.tbl_Item_Details_ID.ID_DetFunc = dbo.tbl_ILU_J_DETFUNC.J_DETFUNC_ID
> LEFT OUTER JOIN
> dbo.tbl_ILU_N_TFUL ON
> dbo.tbl_Item_Details_ID.ID_Top_Fuel = dbo.tbl_ILU_N_TFUL.N_TFUL_ID LEFT
> OUTER JOIN
> dbo.tbl_ILU_O_GROP ON
> dbo.tbl_Item_Details_ID.ID_Product_Group = dbo.tbl_ILU_O_GROP.O_GROP_ID
> LEFT OUTER JOIN
> dbo.tbl_ILU_C_BRND ON
> dbo.tbl_Item_Details_ID.ID_Brand = dbo.tbl_ILU_C_BRND.C_BRND_ID LEFT
> OUTER JOIN
> dbo.tbl_ILU_K_FCTN ON
> dbo.tbl_Item_Details_ID.ID_Function = dbo.tbl_ILU_K_FCTN.K_FCTN_ID LEFT
> OUTER JOIN
> dbo.tbl_ILU_M_APPL ON
> dbo.tbl_Item_Details_ID.ID_Application = dbo.tbl_ILU_M_APPL.M_APPL_ID
> LEFT OUTER JOIN
> dbo.tbl_ILU_P_PLNSG ON
> dbo.tbl_Item_Details_ID.ID_Planning_Sub_Group =
> dbo.tbl_ILU_P_PLNSG.P_PLNSG_ID LEFT OUTER JOIN
> dbo.tbl_ILU_O_PLANG ON
> dbo.tbl_Item_Details_ID.ID_Planning_Group =
> dbo.tbl_ILU_O_PLANG.O_PLANG_ID LEFT OUTER JOIN
> dbo.tbl_ILU_L_OWNR ON
> dbo.tbl_Item_Details_ID.ID_Owner = dbo.tbl_ILU_L_OWNR.L_OWNR_ID LEFT
> OUTER JOIN
> dbo.tbl_ILU_H_COLR ON
> dbo.tbl_Item_Details_ID.ID_Colour = dbo.tbl_ILU_H_COLR.H_COLR_ID LEFT
> OUTER JOIN
> dbo.tbl_ILU_F_DESC ON
> dbo.tbl_Item_Details_ID.ID_Function_Description =
> dbo.tbl_ILU_F_DESC.F_DESC_ID LEFT OUTER JOIN
> dbo.tbl_ILU_D_RANG ON
> dbo.tbl_Item_Details_ID.ID_Range = dbo.tbl_ILU_D_RANG.D_RANG_ID LEFT
> OUTER JOIN
> dbo.tbl_ILU_B_BTYP ON
> dbo.tbl_Item_Details_ID.ID_Brand_Type = dbo.tbl_ILU_B_BTYP.B_BTYP_ID
> LEFT OUTER JOIN
> dbo.tbl_ILU_Z_PTYP ON
> dbo.tbl_Item_Details_ID.ID_Product_Type = dbo.tbl_ILU_Z_PTYP.Z_PTYP_ID
> CREATE VIEW dbo.vw_Customer_Details
> AS
> SELECT dbo.tbl_Customer_Details_CD.CD_Company_Number,
> dbo.tbl_Customer_Details_CD.CD_Customer_Number,
> dbo.tbl_Customer_Details_CD.CD_Dseq,
> dbo.tbl_Customer_Details_CD.CD_Customer_Name,
> dbo.tbl_Customer_Details_CD.CD_Customer_Address_1,
> dbo.tbl_Customer_Details_CD.CD_Customer_Address_2,
> dbo.tbl_Customer_Details_CD.CD_Customer_Address_3,
> dbo.tbl_Customer_Details_CD.CD_Customer_Address_4,
> dbo.tbl_Customer_Details_CD.CD_Customer_Address_5,
> dbo.tbl_Customer_Details_CD.CD_Post_Code_1,
> dbo.tbl_Customer_Details_CD.CD_Post_Code_2,
> dbo.tbl_Customer_Details_CD.CD_Customer_Group_1,
> dbo.tbl_Customer_Details_CD.CD_Customer_Group_2,
> dbo.tbl_Customer_Details_CD.CD_Customer_Group_3,
> dbo.tbl_Customer_Details_CD.CD_Customer_Group_4,
> dbo.tbl_Customer_Details_CD.CD_Region,
> dbo.tbl_Customer_Details_CD.CD_Credit_Limit,
> dbo.tbl_Customer_Details_CD.CD_Customer_Contact,
> dbo.tbl_Customer_Details_CD.CD_Phone_Number,
> dbo.tbl_Customer_Details_CD.CD_Date_Account_Opened ,
> dbo.tbl_Customer_Details_CD.CD_Bank_Account_Number ,
> dbo.tbl_Customer_Details_CD.CD_Bank_Account_Name,
> dbo.tbl_Customer_Details_CD.CD_Bank_Address_1,
> dbo.tbl_Customer_Details_CD.CD_Bank_Address_2,
> dbo.tbl_Customer_Details_CD.CD_Credit_Controller,
> dbo.tbl_Credit_Controller.CC_Description,
> dbo.tbl_Customer_Details_CD.CD_Customer_Group,
> dbo.tbl_CLU_Z_CGT.Z_Customer_Group_Type_Descriptio n,
> dbo.tbl_Customer_Details_CD.CD_Customer_Parent,
> dbo.tbl_CLU_Y_CPT.Y_Customer_Parent_Type_Descripti on,
> dbo.tbl_Customer_Details_CD.CD_Sales_Region,
> dbo.tbl_CLU_A_SRGN.A_Sales_Region_Description,
> dbo.tbl_Customer_Details_CD.CD_Business_Type,
> dbo.tbl_CLU_B_BTYP.B_Business_Type_Description,
> dbo.tbl_Customer_Details_CD.CD_Distribution_Channe l,
> dbo.tbl_CLU_C_DCNL.C_Distribution_Channel_Descript ion,
> dbo.tbl_Customer_Details_CD.CD_Distribution_Cluste r,
> dbo.tbl_CLU_D_DCSR.D_Distribution_Cluster_Descript ion,
> dbo.tbl_Customer_Details_CD.CD_Delivery_Type,
> dbo.tbl_CLU_E_DTYP.E_Delivery_Type_Description,
> dbo.tbl_Customer_Details_CD.CD_Marketing_Director,
> dbo.tbl_CLU_F_MDR.F_Marketing_Director_Resposibili ty_Description,
> dbo.tbl_Customer_Details_CD.CD_Sales_Director,
> dbo.tbl_CLU_G_SDR.G_Sales_Director_Responsibility_ Description,
> dbo.tbl_Customer_Details_CD.CD_Account_Manager,
> dbo.tbl_CLU_H_AMR.H_Account_Manager_Responsibility _Description,
> dbo.tbl_Customer_Details_CD.CD_Date_Account_Opened _PC,
> dbo.tbl_Customer_Details_CD.CD_Consolidated_Custom er,
> dbo.tbl_CLU_I_CNSL.I_Consolidated_Customer_Descrip tion
> FROM dbo.tbl_Customer_Details_CD LEFT OUTER JOIN
> dbo.tbl_CLU_I_CNSL ON
> dbo.tbl_Customer_Details_CD.CD_Consolidated_Custom er =
> dbo.tbl_CLU_I_CNSL.I_CNSL_ID LEFT OUTER JOIN
> dbo.tbl_Credit_Controller ON
> dbo.tbl_Customer_Details_CD.CD_Credit_Controller =
> dbo.tbl_Credit_Controller.CC_ID LEFT OUTER JOIN
> dbo.tbl_CLU_H_AMR ON
> dbo.tbl_Customer_Details_CD.CD_Account_Manager =
> dbo.tbl_CLU_H_AMR.H_AMR_ID LEFT OUTER JOIN
> dbo.tbl_CLU_G_SDR ON
> dbo.tbl_Customer_Details_CD.CD_Sales_Director =
> dbo.tbl_CLU_G_SDR.G_SDR_ID LEFT OUTER JOIN
> dbo.tbl_CLU_F_MDR ON
> dbo.tbl_Customer_Details_CD.CD_Marketing_Director =
> dbo.tbl_CLU_F_MDR.F_MDR_ID LEFT OUTER JOIN
> dbo.tbl_CLU_E_DTYP ON
> dbo.tbl_Customer_Details_CD.CD_Delivery_Type =
> dbo.tbl_CLU_E_DTYP.E_DTYP_ID LEFT OUTER JOIN
> dbo.tbl_CLU_D_DCSR ON
> dbo.tbl_Customer_Details_CD.CD_Distribution_Cluste r =
> dbo.tbl_CLU_D_DCSR.D_DCSR_ID LEFT OUTER JOIN
> dbo.tbl_CLU_C_DCNL ON
> dbo.tbl_Customer_Details_CD.CD_Distribution_Channe l =
> dbo.tbl_CLU_C_DCNL.C_DCNL_ID LEFT OUTER JOIN
> dbo.tbl_CLU_B_BTYP ON
> dbo.tbl_Customer_Details_CD.CD_Business_Type =
> dbo.tbl_CLU_B_BTYP.B_BTYP_ID LEFT OUTER JOIN
> dbo.tbl_CLU_A_SRGN ON
> dbo.tbl_Customer_Details_CD.CD_Sales_Region =
> dbo.tbl_CLU_A_SRGN.A_SRGN_ID LEFT OUTER JOIN
> dbo.tbl_CLU_Y_CPT ON
> dbo.tbl_Customer_Details_CD.CD_Customer_Parent =
> dbo.tbl_CLU_Y_CPT.Y_CPT_ID LEFT OUTER JOIN
> dbo.tbl_CLU_Z_CGT ON
> dbo.tbl_Customer_Details_CD.CD_Customer_Group =
> dbo.tbl_CLU_Z_CGT.Z_CGT_ID
>
> The above should give you some idea of the data, I haven't include the
> scripts for the base tables as this would take considerable time
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!

Incorrect columns returned by view

When I create a view consisting of an inner join between a view and a
table the columns refernced in the the view are returned incorrectly,
example

select id.itemcode, id.description, iv.linevalue, iv.vatvalue from
dbo.tbl_itemdetails id inner join dbo.vw_invoices iv where
dbo.tbl_itemdetails.itemcode = dbo.vw_invoices.itemcode

The actual value that is returned from the view is the column
immediately to the left of the linevalue column, ie stockroomThe code you have posted isn't correct syntax, you've missed the ON clause.

One possibility for you: Could it be that you have some control characters
such as carriage return/line feed in one of the columns you are returning?
Special characters sometimes cause formatting problems when displaying data
in Query Analyzer.

If you need more help please post some code we can run that will reproduce
the problem: DDL (CREATE TABLE statement(s) for the table(s)), sample data
(INSERT statements) and the actual definition of the view.

--
David Portas
SQL Server MVP
--|||Yeah it was just a quick rehash of the view, limiting the information
for demo purposes the actual view(vw_test) is below:

CREATE VIEW dbo.vw_test
AS
SELECT dbo.vw_Invoices_I.ID_Company_Number,
dbo.vw_Invoices_I.ID_Item_Code, dbo.vw_Invoices_I.I_Order_Number,
dbo.vw_Invoices_I.I_Order_Line_Number,
dbo.vw_Invoices_I.I_Invoice_Number, dbo.vw_Invoices_I.I_Customer_Number,
dbo.vw_Invoices_I.I_Delivery_Address_Code,
dbo.vw_Invoices_I.I_Line_Value *
dbo.tbl_Lagged_Sales.Percentage_Of_Sales AS Expr1,
dbo.vw_Invoices_I.I_VAT_Value,
dbo.vw_Invoices_I.I_Discount_Value, dbo.vw_Invoices_I.I_Standard_Cost,
dbo.vw_Invoices_I.I_Line_Cost_Value
FROM dbo.tbl_Lagged_Sales INNER JOIN
dbo.vw_Invoices_I ON
dbo.tbl_Lagged_Sales.Supplier_Code = dbo.vw_Invoices_I.ID_Company AND
dbo.tbl_Lagged_Sales.Lag_Product_Group =
dbo.vw_Invoices_I.ID_Product_GroupHi

if exists (select * from dbo.sysobjects where id =
object_id(N'[dbo].[tbl_Invoices_I_DB_TEST]') and OBJECTPROPERTY(id,
N'IsUserTable') = 1)
drop table [dbo].[tbl_Invoices_I_DB_TEST]
GO

CREATE TABLE [dbo].[tbl_Invoices_I_DB_TEST] (
[I_Company_Number] [char] (2) COLLATE Latin1_General_CI_AS NOT NULL ,
[I_Order_Number] [char] (7) COLLATE Latin1_General_CI_AS NOT NULL ,
[I_Order_Line_Number] [smallint] NOT NULL ,
[I_Invoice_Number] [char] (7) COLLATE Latin1_General_CI_AS NOT NULL ,
[I_Disp_Seq_No] [char] (3) COLLATE Latin1_General_CI_AS NOT NULL ,
[I_Item_Code] [char] (15) COLLATE Latin1_General_CI_AS NULL ,
[I_Pack_Item_Code] [char] (15) COLLATE Latin1_General_CI_AS NULL ,
[I_Stockroom] [char] (2) COLLATE Latin1_General_CI_AS NULL ,
[I_Line_Value] [numeric](17, 2) NOT NULL ,
[I_VAT_Value] [numeric](17, 2) NULL ,
[I_Discount_Value] [numeric](17, 2) NULL ,
[I_Standard_Cost] [numeric](17, 2) NULL ,
[I_Line_Quantity] [numeric](13, 3) NOT NULL ,
[I_Week_Number] [int] NULL ,
[I_Period_Number] [int] NULL ,
[I_Transaction_Type] [smallint] NULL ,
[I_Transaction_Date] [int] NULL ,
[I_Customer_Number] [char] (8) COLLATE Latin1_General_CI_AS NULL ,
[I_Delivery_Address_Code] [char] (3) COLLATE Latin1_General_CI_AS NULL
,
[I_Line_Cost_Value] [numeric](17, 2) NOT NULL ,
[I_Status] [char] (1) COLLATE Latin1_General_CI_AS NULL ,
[I_Parent_Line_Number] [smallint] NULL ,
[I_Reason_Code] [char] (1) COLLATE Latin1_General_CI_AS NULL ,
[I_Print_Flag] [char] (1) COLLATE Latin1_General_CI_AS NULL ,
[I_Sales_Analysis_Update_Flag] [char] (1) COLLATE Latin1_General_CI_AS
NULL ,
[I_Item_Type] [char] (1) COLLATE Latin1_General_CI_AS NULL ,
[I_Sales_Type] [int] NULL ,
[I_Month_Number] [tinyint] NOT NULL ,
[I_Year_Number] [smallint] NOT NULL ,
[I_Transaction_Date_PC] [datetime] NOT NULL ,
[I_Gross_Margin] [numeric](17, 2) NULL ,
[I_Date_Downloaded] [datetime] NULL ,
[Flagged_for_Exception] [bit] NULL
) ON [PRIMARY]
GO

CREATE VIEW dbo.vw_Invoices_I
AS
SELECT dbo.vw_Item_Details_ID.*, dbo.tbl_Invoices_I_DB_TEST.*,
dbo.vw_Customer_Details.*
FROM dbo.tbl_Invoices_I_DB_TEST INNER JOIN
dbo.vw_Customer_Details ON
dbo.tbl_Invoices_I_DB_TEST.I_Company_Number =
dbo.vw_Customer_Details.CD_Company_Number AND
dbo.tbl_Invoices_I_DB_TEST.I_Customer_Number =
dbo.vw_Customer_Details.CD_Customer_Number AND
dbo.tbl_Invoices_I_DB_TEST.I_Delivery_Address_Code
= dbo.vw_Customer_Details.CD_Dseq INNER JOIN
dbo.vw_Item_Details_ID ON
dbo.tbl_Invoices_I_DB_TEST.I_Company_Number =
dbo.vw_Item_Details_ID.ID_Company_Number AND
dbo.tbl_Invoices_I_DB_TEST.I_Item_Code =
dbo.vw_Item_Details_ID.ID_Item_Code

CREATE VIEW dbo.vw_Item_Details_ID
AS
SELECT dbo.tbl_Item_Details_ID.ID_Company_Number,
dbo.tbl_Item_Details_ID.ID_Item_Code,
dbo.tbl_Item_Details_ID.ID_Description,
dbo.tbl_Item_Details_ID.ID_STD_Cost,
dbo.tbl_Item_Details_ID.ID_Product_Type,
dbo.tbl_ILU_Z_PTYP.Z_Product_Type_Description,
dbo.tbl_Item_Details_ID.ID_Company,
dbo.tbl_ILU_A_COMP.A_Company_Description,
dbo.tbl_Item_Details_ID.ID_Brand_Type,
dbo.tbl_ILU_B_BTYP.B_Brand_Type_Description,
dbo.tbl_Item_Details_ID.ID_Brand,
dbo.tbl_ILU_C_BRND.C_Brand_Description,
dbo.tbl_Item_Details_ID.ID_Range,
dbo.tbl_ILU_D_RANG.D_Range_Description, dbo.tbl_Item_Details_ID.ID_Item,
dbo.tbl_ILU_E_ITEM.E_Item_Description,
dbo.tbl_Item_Details_ID.ID_Function_Description,
dbo.tbl_ILU_F_DESC.F_Description_Description,
dbo.tbl_Item_Details_ID.ID_Det_Fuel,
dbo.tbl_ILU_G_DET_FUEL.G_Det_Fuel_Description,
dbo.tbl_Item_Details_ID.ID_Colour,
dbo.tbl_ILU_H_COLR.H_Colour_Description,
dbo.tbl_Item_Details_ID.ID_TypeCat,
dbo.tbl_ILU_I_TYPECAT.I_TypeCat_Description,
dbo.tbl_Item_Details_ID.ID_DetFunc,
dbo.tbl_ILU_J_DETFUNC.J_DETFUNC_Description,
dbo.tbl_Item_Details_ID.ID_Function,
dbo.tbl_ILU_K_FCTN.K_Function_Description,
dbo.tbl_Item_Details_ID.ID_Owner,
dbo.tbl_ILU_L_OWNR.L_Owner_Description,
dbo.tbl_Item_Details_ID.ID_Application,
dbo.tbl_ILU_M_APPL.M_Application_Description,
dbo.tbl_Item_Details_ID.ID_Planning_Group,
dbo.tbl_ILU_O_PLANG.O_Planning_Group_Description,
dbo.tbl_Item_Details_ID.ID_Planning_Sub_Group,

dbo.tbl_ILU_P_PLNSG.P_Planning_Sub_Group_Descripti on,
dbo.tbl_Item_Details_ID.ID_Product_Group,
dbo.tbl_ILU_O_GROP.O_PoductGroup_Description,
dbo.tbl_Item_Details_ID.ID_Top_Fuel,
dbo.tbl_ILU_N_TFUL.N_TopFuel_Description,
dbo.tbl_Item_Details_ID.ID_Date_Last_Manufactured,
dbo.tbl_Item_Details_ID.ID_Model, dbo.tbl_ILU_P_MODL.P_Model_Description
FROM dbo.tbl_Item_Details_ID INNER JOIN
dbo.tbl_ILU_P_MODL ON
dbo.tbl_Item_Details_ID.ID_Model = dbo.tbl_ILU_P_MODL.P_MODL_ID LEFT
OUTER JOIN
dbo.tbl_ILU_A_COMP ON
dbo.tbl_Item_Details_ID.ID_Company = dbo.tbl_ILU_A_COMP.A_COMP_ID LEFT
OUTER JOIN
dbo.tbl_ILU_I_TYPECAT ON
dbo.tbl_Item_Details_ID.ID_TypeCat = dbo.tbl_ILU_I_TYPECAT.I_TYPECAT_ID
LEFT OUTER JOIN
dbo.tbl_ILU_E_ITEM ON
dbo.tbl_Item_Details_ID.ID_Item = dbo.tbl_ILU_E_ITEM.E_ITEM_ID LEFT
OUTER JOIN
dbo.tbl_ILU_G_DET_FUEL ON
dbo.tbl_Item_Details_ID.ID_Det_Fuel =
dbo.tbl_ILU_G_DET_FUEL.G_DET_FUEL_ID LEFT OUTER JOIN
dbo.tbl_ILU_J_DETFUNC ON
dbo.tbl_Item_Details_ID.ID_DetFunc = dbo.tbl_ILU_J_DETFUNC.J_DETFUNC_ID
LEFT OUTER JOIN
dbo.tbl_ILU_N_TFUL ON
dbo.tbl_Item_Details_ID.ID_Top_Fuel = dbo.tbl_ILU_N_TFUL.N_TFUL_ID LEFT
OUTER JOIN
dbo.tbl_ILU_O_GROP ON
dbo.tbl_Item_Details_ID.ID_Product_Group = dbo.tbl_ILU_O_GROP.O_GROP_ID
LEFT OUTER JOIN
dbo.tbl_ILU_C_BRND ON
dbo.tbl_Item_Details_ID.ID_Brand = dbo.tbl_ILU_C_BRND.C_BRND_ID LEFT
OUTER JOIN
dbo.tbl_ILU_K_FCTN ON
dbo.tbl_Item_Details_ID.ID_Function = dbo.tbl_ILU_K_FCTN.K_FCTN_ID LEFT
OUTER JOIN
dbo.tbl_ILU_M_APPL ON
dbo.tbl_Item_Details_ID.ID_Application = dbo.tbl_ILU_M_APPL.M_APPL_ID
LEFT OUTER JOIN
dbo.tbl_ILU_P_PLNSG ON
dbo.tbl_Item_Details_ID.ID_Planning_Sub_Group =
dbo.tbl_ILU_P_PLNSG.P_PLNSG_ID LEFT OUTER JOIN
dbo.tbl_ILU_O_PLANG ON
dbo.tbl_Item_Details_ID.ID_Planning_Group =
dbo.tbl_ILU_O_PLANG.O_PLANG_ID LEFT OUTER JOIN
dbo.tbl_ILU_L_OWNR ON
dbo.tbl_Item_Details_ID.ID_Owner = dbo.tbl_ILU_L_OWNR.L_OWNR_ID LEFT
OUTER JOIN
dbo.tbl_ILU_H_COLR ON
dbo.tbl_Item_Details_ID.ID_Colour = dbo.tbl_ILU_H_COLR.H_COLR_ID LEFT
OUTER JOIN
dbo.tbl_ILU_F_DESC ON
dbo.tbl_Item_Details_ID.ID_Function_Description =
dbo.tbl_ILU_F_DESC.F_DESC_ID LEFT OUTER JOIN
dbo.tbl_ILU_D_RANG ON
dbo.tbl_Item_Details_ID.ID_Range = dbo.tbl_ILU_D_RANG.D_RANG_ID LEFT
OUTER JOIN
dbo.tbl_ILU_B_BTYP ON
dbo.tbl_Item_Details_ID.ID_Brand_Type = dbo.tbl_ILU_B_BTYP.B_BTYP_ID
LEFT OUTER JOIN
dbo.tbl_ILU_Z_PTYP ON
dbo.tbl_Item_Details_ID.ID_Product_Type = dbo.tbl_ILU_Z_PTYP.Z_PTYP_ID

CREATE VIEW dbo.vw_Customer_Details
AS
SELECT dbo.tbl_Customer_Details_CD.CD_Company_Number,
dbo.tbl_Customer_Details_CD.CD_Customer_Number,
dbo.tbl_Customer_Details_CD.CD_Dseq,
dbo.tbl_Customer_Details_CD.CD_Customer_Name,
dbo.tbl_Customer_Details_CD.CD_Customer_Address_1,
dbo.tbl_Customer_Details_CD.CD_Customer_Address_2,
dbo.tbl_Customer_Details_CD.CD_Customer_Address_3,
dbo.tbl_Customer_Details_CD.CD_Customer_Address_4,
dbo.tbl_Customer_Details_CD.CD_Customer_Address_5,
dbo.tbl_Customer_Details_CD.CD_Post_Code_1,
dbo.tbl_Customer_Details_CD.CD_Post_Code_2,
dbo.tbl_Customer_Details_CD.CD_Customer_Group_1,
dbo.tbl_Customer_Details_CD.CD_Customer_Group_2,
dbo.tbl_Customer_Details_CD.CD_Customer_Group_3,
dbo.tbl_Customer_Details_CD.CD_Customer_Group_4,
dbo.tbl_Customer_Details_CD.CD_Region,
dbo.tbl_Customer_Details_CD.CD_Credit_Limit,
dbo.tbl_Customer_Details_CD.CD_Customer_Contact,
dbo.tbl_Customer_Details_CD.CD_Phone_Number,
dbo.tbl_Customer_Details_CD.CD_Date_Account_Opened ,

dbo.tbl_Customer_Details_CD.CD_Bank_Account_Number ,
dbo.tbl_Customer_Details_CD.CD_Bank_Account_Name,
dbo.tbl_Customer_Details_CD.CD_Bank_Address_1,
dbo.tbl_Customer_Details_CD.CD_Bank_Address_2,
dbo.tbl_Customer_Details_CD.CD_Credit_Controller,
dbo.tbl_Credit_Controller.CC_Description,
dbo.tbl_Customer_Details_CD.CD_Customer_Group,

dbo.tbl_CLU_Z_CGT.Z_Customer_Group_Type_Descriptio n,
dbo.tbl_Customer_Details_CD.CD_Customer_Parent,

dbo.tbl_CLU_Y_CPT.Y_Customer_Parent_Type_Descripti on,
dbo.tbl_Customer_Details_CD.CD_Sales_Region,
dbo.tbl_CLU_A_SRGN.A_Sales_Region_Description,
dbo.tbl_Customer_Details_CD.CD_Business_Type,
dbo.tbl_CLU_B_BTYP.B_Business_Type_Description,
dbo.tbl_Customer_Details_CD.CD_Distribution_Channe l,

dbo.tbl_CLU_C_DCNL.C_Distribution_Channel_Descript ion,
dbo.tbl_Customer_Details_CD.CD_Distribution_Cluste r,

dbo.tbl_CLU_D_DCSR.D_Distribution_Cluster_Descript ion,
dbo.tbl_Customer_Details_CD.CD_Delivery_Type,
dbo.tbl_CLU_E_DTYP.E_Delivery_Type_Description,
dbo.tbl_Customer_Details_CD.CD_Marketing_Director,

dbo.tbl_CLU_F_MDR.F_Marketing_Director_Resposibili ty_Description,
dbo.tbl_Customer_Details_CD.CD_Sales_Director,

dbo.tbl_CLU_G_SDR.G_Sales_Director_Responsibility_ Description,
dbo.tbl_Customer_Details_CD.CD_Account_Manager,

dbo.tbl_CLU_H_AMR.H_Account_Manager_Responsibility _Description,
dbo.tbl_Customer_Details_CD.CD_Date_Account_Opened _PC,

dbo.tbl_Customer_Details_CD.CD_Consolidated_Custom er,
dbo.tbl_CLU_I_CNSL.I_Consolidated_Customer_Descrip tion
FROM dbo.tbl_Customer_Details_CD LEFT OUTER JOIN
dbo.tbl_CLU_I_CNSL ON
dbo.tbl_Customer_Details_CD.CD_Consolidated_Custom er =
dbo.tbl_CLU_I_CNSL.I_CNSL_ID LEFT OUTER JOIN
dbo.tbl_Credit_Controller ON
dbo.tbl_Customer_Details_CD.CD_Credit_Controller =
dbo.tbl_Credit_Controller.CC_ID LEFT OUTER JOIN
dbo.tbl_CLU_H_AMR ON
dbo.tbl_Customer_Details_CD.CD_Account_Manager =
dbo.tbl_CLU_H_AMR.H_AMR_ID LEFT OUTER JOIN
dbo.tbl_CLU_G_SDR ON
dbo.tbl_Customer_Details_CD.CD_Sales_Director =
dbo.tbl_CLU_G_SDR.G_SDR_ID LEFT OUTER JOIN
dbo.tbl_CLU_F_MDR ON
dbo.tbl_Customer_Details_CD.CD_Marketing_Director =
dbo.tbl_CLU_F_MDR.F_MDR_ID LEFT OUTER JOIN
dbo.tbl_CLU_E_DTYP ON
dbo.tbl_Customer_Details_CD.CD_Delivery_Type =
dbo.tbl_CLU_E_DTYP.E_DTYP_ID LEFT OUTER JOIN
dbo.tbl_CLU_D_DCSR ON
dbo.tbl_Customer_Details_CD.CD_Distribution_Cluste r =
dbo.tbl_CLU_D_DCSR.D_DCSR_ID LEFT OUTER JOIN
dbo.tbl_CLU_C_DCNL ON
dbo.tbl_Customer_Details_CD.CD_Distribution_Channe l =
dbo.tbl_CLU_C_DCNL.C_DCNL_ID LEFT OUTER JOIN
dbo.tbl_CLU_B_BTYP ON
dbo.tbl_Customer_Details_CD.CD_Business_Type =
dbo.tbl_CLU_B_BTYP.B_BTYP_ID LEFT OUTER JOIN
dbo.tbl_CLU_A_SRGN ON
dbo.tbl_Customer_Details_CD.CD_Sales_Region =
dbo.tbl_CLU_A_SRGN.A_SRGN_ID LEFT OUTER JOIN
dbo.tbl_CLU_Y_CPT ON
dbo.tbl_Customer_Details_CD.CD_Customer_Parent =
dbo.tbl_CLU_Y_CPT.Y_CPT_ID LEFT OUTER JOIN
dbo.tbl_CLU_Z_CGT ON
dbo.tbl_Customer_Details_CD.CD_Customer_Group =
dbo.tbl_CLU_Z_CGT.Z_CGT_ID

The above should give you some idea of the data, I haven't include the
scripts for the base tables as this would take considerable time

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!