?
Solved

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

Posted on 2011-03-10
9
Medium Priority
?
452 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 2000 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

770 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