Solved

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

Posted on 2011-03-10
9
446 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

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…
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.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

863 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

27 Experts available now in Live!

Get 1:1 Help Now