Solved

Need some help with CREATE A  VIEW

Posted on 2011-03-10
6
353 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
  • 3
  • 3
6 Comments
 
LVL 40

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
[Webinar] Disaster Recovery and Cloud Management

Learn from Unigma and CloudBerry industry veterans which providers are best for certain use cases and how to lower cloud costs, how to grow your Managed Services practice in IaaS clouds, and how to utilize public cloud for Disaster Recovery

 
LVL 40

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 40

Expert Comment

by:Sharath
ID: 35106394
Glad I could help you :)
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

Suggested Solutions

Title # Comments Views Activity
combining condition to rerun if failure within BEGIN..END 27 87
Authentication error 1 39
all records from previous month 6 45
SQL server is using more virtual memory. 5 68
Long way back, we had to take help from third party tools in order to encrypt and decrypt data.  Gradually Microsoft understood the need for this feature and started to implement it by building functionality into SQL Server. Finally, with SQL 2008, …
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
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 …
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

920 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

16 Experts available now in Live!

Get 1:1 Help Now