Solved

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

Posted on 2011-03-10
9
449 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
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

INTRODUCTION: While tying your database objects into builds and your enterprise source control system takes a third-party product (like Visual Studio Database Edition or Red-Gate's SQL Source Control), you can achieve some protection using a sing…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

726 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