473,418 Members | 2,100 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,418 software developers and data experts.

Create a specific view in SQL server

4
In the last few days I have developed a small database within SQL Server, with the aim of improving my knowledge.

For now, I need to create a view (for the analytics team), to which the following data should be reported in the view.

➤ Order ID
➤ Date and time of order creation
➤ Customer's first and last name
➤ Delivery date
➤ Item code and description
➤ Quantity demanded
➤ Amount to be paid
➤ Payment Type Description
➤ Total order weight
➤ Total order volume

For the moment I am stuck in this part, and therefore, I would need the query to compose this view by reporting the above data.
---

The last question I ask you is:
To create the view I would first have to create a relationship between the items, for example: Between items in the item table and items in the order table?

Expand|Select|Wrap|Line Numbers
  1. -- The query I'm using to create the view, but I think something is missing or not correct.
  2.  
  3. USE [TestExec]
  4. GO
  5.  
  6. CREATE VIEW OrdersToShip AS
  7. SELECT O.[ID_Orders]
  8. ,O.[DataInsert]
  9. ,C.[Name]
  10. ,C.[Surname]
  11. ,O.[Shipping]
  12. ,A.[Article]
  13. ,A.[Description] 
  14. ,O.[Quantity]
  15. ,O.[Quantity] * A.[Unit_Cost]
  16. ,TP.[Description]
  17. ,O.[Quantity] * 
  18. ,O.[Quantity] * A.[Net_Weight_Kg]
  19.  
  20. FROM ORDERS O
  21. INNER JOIN CUSTOMERS C ON O.Client_ID = C.Client_ID
  22. INNER JOIN ARTICLES A ON O.ARTICLE = A.ARTICLE
  23. INNER JOIN TYPEPAYMENT TP ON O.PAYMENT_ID = TP.ID_PAYMENT
  24.  
  25. GO
  26.  
  27. -- Articles table
  28.  
  29. CREATE TABLE [DW]. [Articles] (
  30. [Article] [nvarchar] (30) NOT NULL,
  31. [Description] [nvarchar] (150) NOT NULL,
  32. [Unit_di_misura] [nvarchar] (20) NOT NULL,
  33. [Pieces_per_Box] [nvarchar] (20) NOT NULL,
  34. [Box_for_Pallet] [int] NOT NULL,
  35. [Unit_Cost] [float] NOT NULL,
  36. [Net_Weight_Kg] [float] NOT NULL,
  37. [Height_cm] [int] NOT NULL,
  38. [Length_cm] [int] NOT NULL,
  39. [Width_cm] [int] NOT NULL,
  40. [DataInsert] [datetime] NOT NULL
  41.  
  42. -- Customers table
  43.  
  44. CREATE TABLE [DW]. [Customers] (
  45. [Client_ID] [int] IDENTITY (1,1) NOT NULL,
  46. [Name] [nvarchar] (50) NOT NULL,
  47. [Surname] [nvarchar] (50) NOT NULL,
  48. [Social_Reason] [nvarchar] (80) NULL,
  49. [CF_PIVA] [nvarchar] (30) NOT NULL,
  50. [email] [nvarchar] (80) NOT NULL,
  51. [Telephone] [nvarchar] (30) NOT NULL,
  52. [Address] [nvarchar] (50) NOT NULL,
  53. [CAP] [int] NOT NULL,
  54. [City] [nvarchar] (50) NOT NULL,
  55. [Province] [nvarchar] (50) NOT NULL,
  56. [Country] [nvarchar] (50) NOT NULL,
  57. [DataInsert] [datetime] NOT NULL,
  58. CONSTRAINT [PK_ID_Cliente] PRIMARY KEY CLUSTERED 
  59.  
  60. -- Orders table
  61.  
  62. CREATE TABLE [DW]. [Orders] (
  63. [ID_Orders] [int] IDENTITY (1,1) NOT NULL,
  64. [Customer] [nvarchar] (80) NOT NULL,
  65. [Client_ID] [int] NOT NULL,
  66. [Article] [nvarchar] (30) NOT NULL,
  67. [Quantity] [int] NOT NULL,
  68. [Delivery] [date] NULL,
  69. [Payment] [nvarchar] (50) NOT NULL,
  70. [Payment_ID] [int] NULL,
  71. [DataInsert] [datetime] NOT NULL,
  72. [Shipping] [date] NULL,
  73.  CONSTRAINT [PK_Ordini] PRIMARY KEY CLUSTERED
  74.  
  75. -- Payment type table
  76.  
  77. CREATE TABLE [DW]. [TypePayment] (
  78. [ID_Payment] [int] IDENTITY (1,1) NOT NULL,
  79. [Payment] [nvarchar] (50) NOT NULL,
  80. [Description] [nchar] (150) NULL,
  81.  CONSTRAINT [PK_ID_Payment] PRIMARY KEY CLUSTERED
  82.  
  83.  
Jan 19 '22 #1
0 20623

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: M. Mehta | last post by:
It seems that you can not create a materialized view if you are using outer joins...can someone please verify this? Thanks M. Mehta Please follow my example below: created 2 tables:
5
by: ljlevend2 | last post by:
Is there any way to create a local server during runtime? For example, if you add an existing Web Site to a Solution from within Visual Studio (by right clicking the solution in the Solution...
0
by: qfchen | last post by:
Hi I'm using Visual Studio 2005 for database application. the database is MS access. I need to create a view in server explorer, when I right click on view folder, I can't see "Add New View" from...
3
by: zgh1970 | last post by:
Hi, All, We have a database on db2 udb aix. The database has federated server to db2 mainframe. Now We have already catalog database of db2/400 on the db2 UDB aix server. I tried to create new...
1
by: NithyaJai | last post by:
Hai, I got a doubt on creating a view? Is that passible to create a view in MS Access 2000....... if so plz help me to do it... Thanks....
1
by: WayneW | last post by:
I need to create a view of tables in 2 databases. Is this possible?
2
nirmalsingh
by: nirmalsingh | last post by:
hai all, i can view only solution explorer , i cant view server explorer window. i am new to .net. what should i do to view server explorer? ...
0
by: rupinder03 | last post by:
I want to create tree view in data grid in vb.net 2005.can anyone tell me hw to create it................its urgent.......plz reply soon..............
1
by: kensushi | last post by:
Hi, Im somewhat new to oracle SP writing. I need to do the following from the SP 1. execute the query 2. create a view and populate with the result of the above query 3 query that view and...
1
by: Liena | last post by:
Hi, How can I redirect from one page to anothe in an specific view from a multiview control? How do I do this in ASP. NET using C#? For ex: prtected void Button_Click(object sender, EventArgs...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.