Solved

Need some help wiht Create a View and inner join 3 tables

Posted on 2011-03-10
9
450 Views
Last Modified: 2012-05-11
Hello,
I need some help with CREATE A  VIEW and inner join.
I ask the question today before without a solution

Question:
I would like to join 3 tables.
 
 A.Lieferungsbedingungenkurzbezeichnung is a number from 0 to 10  (type nvachar)

In a thrid tableTextbausteine are the explication to the numbers (ntext)
Table Textbausteine
--------------------------------
TextbausteinNr     TextbausteinD
(nvachar 16 )          (ntext)      
-----------------------------------  
 0                         pick-up service by car
1                          pick-up service by train
2                          and so on……..
 

I would like to add these explications to the ViewLieferscheine2.
So that the A.Lieferungsbedingungenkurzbezeichnung is not the number but the text of TextbausteinD
 How can I do this?

 500 points with a solution.
Thank you.

Best regards,
Thomas

 I think there error comes from here:
ON A.Lieferungsbedingungenkurzbezeichnung=C.TextbausteinNr\


sql.Format("CREATE VIEW ViewLieferscheine4 AS SELECT\
	   A.LieferscheinNr, A.VersandName1, \
            A.Lieferungsbedingungenkurzbezeichnung,\
            SUM(B.Einheitwert8) AS Gewicht,C.TextbausteinD \

	   FROM Lieferscheine AS A inner join Lieferscheinpositionen AS B\
	   ON A.LieferscheinNr=B.LieferscheinNr\
           inner join Textbausteine AS C\

         	 ON A.Lieferungsbedingungenkurzbezeichnung=C.TextbausteinNr\

	 GROUP BY A.LieferscheinNr,A.VersandName1, \
	 A.Lieferungsbedingungenkurzbezeichnung,C.TextbausteinD");

Open in new window

1.BMP
0
Comment
Question by:tsp2002
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
9 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 35095220
>TextbausteinD NTEXT

please change that data type to NVARCHAR(MAX), and you should be fine.
0
 
LVL 40

Expert Comment

by:lcohan
ID: 35095319
--You could simply do:

SELECT      A.LieferscheinNr, A.VersandName1,
            A.Lieferungsbedingungenkurzbezeichnung,
        SUM(B.Einheitwert8) AS Gewicht,
        C.TextbausteinD,
        C.TextbausteinNr
FROM Lieferscheine AS A
            inner join Lieferscheinpositionen AS B ON A.LieferscheinNr=B.LieferscheinNr
            inner join Textbausteine AS C ON A.Lieferungsbedingungenkurzbezeichnung=C.TextbausteinNr
GROUP BY A.LieferscheinNr,A.VersandName1, A.Lieferungsbedingungenkurzbezeichnung,C.TextbausteinD;


0
 

Author Comment

by:tsp2002
ID: 35106339
--You could simply do:

SELECT      A.LieferscheinNr, A.VersandName1,
            A.Lieferungsbedingungenkurzbezeichnung,
        SUM(B.Einheitwert8) AS Gewicht,
        C.TextbausteinD,
        C.TextbausteinNr
FROM Lieferscheine AS A
            inner join Lieferscheinpositionen AS B ON A.LieferscheinNr=B.LieferscheinNr
            inner join Textbausteine AS C ON A.Lieferungsbedingungenkurzbezeichnung=C.TextbausteinNr
GROUP BY A.LieferscheinNr,A.VersandName1, A.Lieferungsbedingungenkurzbezeichnung,C.TextbausteinD;


NO the same error....will not work
0
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 35106363
if you don't want to change the data type of the column itself (though recommended), you can do it "online" in the query:
SELECT A.LieferscheinNr
   , A.VersandName1 
   , A.Lieferungsbedingungenkurzbezeichnung
   , SUM(B.Einheitwert8) AS Gewicht
   , cast(C.TextbausteinD as nvarchar(max)) TextbausteinD
   , C.TextbausteinNr
FROM Lieferscheine AS A
JOIN Lieferscheinpositionen AS B 
  ON A.LieferscheinNr=B.LieferscheinNr
JOIN Textbausteine AS C 
  ON A.Lieferungsbedingungenkurzbezeichnung=C.TextbausteinNr
GROUP BY A.LieferscheinNr
    , A.VersandName1
    , A.Lieferungsbedingungenkurzbezeichnung
    , cast(C.TextbausteinD as nvarchar(max));

Open in new window

0
 

Author Comment

by:tsp2002
ID: 35106435
wrong syntax in row 1 near of max......is my error message
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 35106484
then you don't have SQL 2005+, or your db is in sql 2000 compatibility mode
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 35106489
and in case you cannot change the compatibility mode to 90 or higher:
SELECT A.LieferscheinNr
   , A.VersandName1 
   , A.Lieferungsbedingungenkurzbezeichnung
   , SUM(B.Einheitwert8) AS Gewicht
   , cast(C.TextbausteinD as nvarchar(4000)) TextbausteinD
   , C.TextbausteinNr
FROM Lieferscheine AS A
JOIN Lieferscheinpositionen AS B 
  ON A.LieferscheinNr=B.LieferscheinNr
JOIN Textbausteine AS C 
  ON A.Lieferungsbedingungenkurzbezeichnung=C.TextbausteinNr
GROUP BY A.LieferscheinNr
    , A.VersandName1
    , A.Lieferungsbedingungenkurzbezeichnung
    , cast(C.TextbausteinD as nvarchar(4000));

Open in new window

0
 

Author Comment

by:tsp2002
ID: 35107232
the type nvachar is no def. system typ = erro message.

I now the answer.....     convert(nvachar,C.TextbausteinD)

SELECT A.LieferscheinNr
   , A.VersandName1 
   , A.Lieferungsbedingungenkurzbezeichnung
   , SUM(B.Einheitwert8) AS Gewicht
   , convert(nvachar,C.TextbausteinD)

   , C.TextbausteinNr
FROM Lieferscheine AS A
JOIN Lieferscheinpositionen AS B 
  ON A.LieferscheinNr=B.LieferscheinNr
JOIN Textbausteine AS C 
  ON A.Lieferungsbedingungenkurzbezeichnung=C.TextbausteinNr
GROUP BY A.LieferscheinNr
    , A.VersandName1
    , A.Lieferungsbedingungenkurzbezeichnung
    , convert(nvachar,C.TextbausteinD);

Open in new window

0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 35107322
sorry, nvarchar
SELECT A.LieferscheinNr
   , A.VersandName1
   , A.Lieferungsbedingungenkurzbezeichnung
   , SUM(B.Einheitwert8) AS Gewicht
   , convert(nvarchar(4000),C.TextbausteinD)

   , C.TextbausteinNr
FROM Lieferscheine AS A
JOIN Lieferscheinpositionen AS B
  ON A.LieferscheinNr=B.LieferscheinNr
JOIN Textbausteine AS C
  ON A.Lieferungsbedingungenkurzbezeichnung=C.TextbausteinNr
GROUP BY A.LieferscheinNr
    , A.VersandName1
    , A.Lieferungsbedingungenkurzbezeichnung
    , convert(nvarchar(4000),C.TextbausteinD);

Open in new window

0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Long way back, we had to take help from third party tools in order to encrypt and decrypt data.  Gradually Microsoft understood the need for this feature and started to implement it by building functionality into SQL Server. Finally, with SQL 2008, …
There have been several questions about Large Transaction Log Files in SQL Server 2008, and how to get rid of them when disk space has become critical. This article will explain how to disable full recovery and implement simple recovery that carries…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question