Solved

Need some help with CREATE A  VIEW

Posted on 2011-03-10
6
356 Views
Last Modified: 2012-05-11
Hello,
I need some help with CREATE a VIEW.

sql.Format("CREATE VIEW ViewLieferscheine2 AS SELECT\
       A.LieferscheinNr, A.VersandName1, A.VersandName2,\
       A.VersandStrassePostfach,CAST(A.VersandPostleitzahl AS VARCHAR(10))AS VersandPostleitzahl,\
       A.VersandOrt,A.VersandLand,A.Lieferscheindatum,\
       A.DebitorenNr, A.Lieferungsbedingungenkurzbezeichnung AS Lieferbedingung,\
       A.FakturiertAktiv AS Fakturiert,SUM(B.Einheitbez13wert) AS Gewicht\

       FROM Lieferscheine AS A inner join Lieferscheinpositionen AS B\
       ON A.LieferscheinNr=B.LieferscheinNr WHERE A.LieferscheinNr<2000000\

       GROUP BY A.LieferscheinNr,A.VersandName1,A.VersandName2,\
       A.VersandStrassePostfach, A.VersandPostleitzahl,\
          A.VersandOrt,A.VersandLand, A.Lieferscheindatum, A.DebitorenNr,\
       A.Lieferungsbedingungenkurzbezeichnung, A.FakturiertAktiv");

This view works just fine, but I would like to add data from a other table.

A.Lieferungsbedingungenkurzbezeichnung AS Lieferbedingung = is a number from 0 to 10  (type nvachar)

In a thrid table Lieferterms are the explication to the numbers (nvachar)
Table Lieferterms
Columns
--------------------------------
Number            Terms
(nvachar)          (nvachar)      
-----------------------------------  
 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 in Lieferbedingung
How can I do this?

So f.e. in Lieferbedingung of my view above should the explication like pick-up serivce by car and not the number 0
500 points with a solution.
Thank you.

Best regards,
Thomas

sql.Format("CREATE VIEW ViewLieferscheine2 AS SELECT\
	 A.LieferscheinNr, A.VersandName1, A.VersandName2,\
	 A.VersandStrassePostfach,CAST(A.VersandPostleitzahl AS VARCHAR(10))AS VersandPostleitzahl,\
	 A.VersandOrt,A.VersandLand,A.Lieferscheindatum,\
	 A.DebitorenNr, A.Lieferungsbedingungenkurzbezeichnung AS Lieferbedingung,\
	 A.FakturiertAktiv AS Fakturiert,SUM(B.Einheitbez13wert) AS Gewicht\

	 FROM Lieferscheine AS A inner join Lieferscheinpositionen AS B\
	 ON A.LieferscheinNr=B.LieferscheinNr WHERE A.LieferscheinNr<2000000\

	 GROUP BY A.LieferscheinNr,A.VersandName1,A.VersandName2,\
	 A.VersandStrassePostfach, A.VersandPostleitzahl,\
   	 A.VersandOrt,A.VersandLand, A.Lieferscheindatum, A.DebitorenNr,\
	 A.Lieferungsbedingungenkurzbezeichnung, A.FakturiertAktiv");

Open in new window

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
  • 3
  • 3
6 Comments
 
LVL 41

Expert Comment

by:Sharath
ID: 35093217
try this
sql.Format("CREATE VIEW ViewLieferscheine2 AS SELECT\
       A.LieferscheinNr, A.VersandName1, A.VersandName2,\
       A.VersandStrassePostfach,CAST(A.VersandPostleitzahl AS VARCHAR(10))AS VersandPostleitzahl,\
       A.VersandOrt,A.VersandLand,A.Lieferscheindatum,\
       A.DebitorenNr, A.Lieferungsbedingungenkurzbezeichnung AS Lieferbedingung,C.Terms\
       A.FakturiertAktiv AS Fakturiert,SUM(B.Einheitbez13wert) AS Gewicht\

       FROM Lieferscheine AS A inner join Lieferscheinpositionen AS B\
       ON A.LieferscheinNr=B.LieferscheinNr\
       inner join Lieferterms AS C on A.Lieferungsbedingungenkurzbezeichnung = C.Number\ 
       WHERE A.LieferscheinNr<2000000\

       GROUP BY A.LieferscheinNr,A.VersandName1,A.VersandName2,\
       A.VersandStrassePostfach, A.VersandPostleitzahl,\
          A.VersandOrt,A.VersandLand, A.Lieferscheindatum, A.DebitorenNr,\
       A.Lieferungsbedingungenkurzbezeichnung, C.Terms,A.FakturiertAktiv");

Open in new window

0
 

Author Comment

by:tsp2002
ID: 35093607
I got this error.
I did a mistake.
The Terms in Table Lieferterms are not nvarchar the type is ntext.
Does the error comes from that?
Please help, thanks

1.BMP
0
 

Author Comment

by:tsp2002
ID: 35094226
in english: you only can compare or sort  the typs text,ntext or image with IS NULL or LIKE
Can you help me?
0
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
LVL 41

Accepted Solution

by:
Sharath earned 500 total points
ID: 35103598
try this.
sql.Format("CREATE VIEW ViewLieferscheine2 AS SELECT\
       A.LieferscheinNr, A.VersandName1, A.VersandName2,\
       A.VersandStrassePostfach,CAST(A.VersandPostleitzahl AS VARCHAR(10))AS VersandPostleitzahl,\
       A.VersandOrt,A.VersandLand,A.Lieferscheindatum,\
       A.DebitorenNr, A.Lieferungsbedingungenkurzbezeichnung AS Lieferbedingung,convert(nvarchar,C.Terms) Terms\
       A.FakturiertAktiv AS Fakturiert,SUM(B.Einheitbez13wert) AS Gewicht\

       FROM Lieferscheine AS A inner join Lieferscheinpositionen AS B\
       ON A.LieferscheinNr=B.LieferscheinNr\
       inner join Lieferterms AS C on A.Lieferungsbedingungenkurzbezeichnung = C.Number\ 
       WHERE A.LieferscheinNr<2000000\

       GROUP BY A.LieferscheinNr,A.VersandName1,A.VersandName2,\
       A.VersandStrassePostfach, A.VersandPostleitzahl,\
          A.VersandOrt,A.VersandLand, A.Lieferscheindatum, A.DebitorenNr,\
       A.Lieferungsbedingungenkurzbezeichnung, convert(nvarchar,C.Terms),A.FakturiertAktiv");

Open in new window

0
 

Author Closing Comment

by:tsp2002
ID: 35106386
thank you, that works.
Have a great weekend.
Best regards,
Thomas
0
 
LVL 41

Expert Comment

by:Sharath
ID: 35106394
Glad I could help you :)
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Suggested Solutions

by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

733 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