Solved

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

Posted on 2011-03-10
9
443 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 142

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 39

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
 
LVL 142

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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

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

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 142

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 142

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

762 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now