Solved

Need some help with CREATE A  VIEW

Posted on 2011-03-10
6
354 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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
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
Unable to save view in SSMS 21 70
Columnstore Indexes - real-time operational analytics 1 35
SQL BULK INSERT Comma Delimited Issue 8 50
Email Notifications for SQL 2005 9 28
INTRODUCTION: While tying your database objects into builds and your enterprise source control system takes a third-party product (like Visual Studio Database Edition or Red-Gate's SQL Source Control), you can achieve some protection using a sing…
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

773 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