Microsoft SQL Server

164K

Solutions

50K

Contributors

Microsoft SQL Server is a suite of relational database management system (RDBMS) products providing multi-user database access functionality.SQL Server is available in multiple versions, typically identified by release year, and versions are subdivided into editions to distinguish between product functionality. Component services include integration (SSIS), reporting (SSRS), analysis (SSAS), data quality, master data, T-SQL and performance tuning.

Share tech news, updates, or what's on your mind.

Sign up to Post

In SQL Server 2012, it would help with development workload and maintenance to create a view with tables and joins specified only once and re-use the view in stored procedures and functions rather than re-specify the tables and joins over and over again.  However, I'm concerned about performance degradation.  If I have a view with table joins but no filters, and I create a recordset that filters on that view in a stored procedure, will SQL Server execute the view, joining every record of every table first, creating a huge result set, and then as a second step filter the huge result set in the stored procedure, or is it intelligent enough to use the filter while it's running the joins from the view?
0
Fundamentals of JavaScript
LVL 13
Fundamentals of JavaScript

Learn the fundamentals of the popular programming language JavaScript so that you can explore the realm of web development.

To return total Revenue as Total Sales by North American region, I created this query that comes blank. not sure what I missed, both tables have common column, TerritoryID and am to filter results for those two years shown

                              SELECT                  TotalDue, Count(*) as Revenue
                              FROM                  AdventureWorks2016.Sales.SalesOrderHeader a
                              INNER JOIN            AdventureWorks2016.Sales.SalesTerritory b
                              ON                        a.TerritoryID = b.TerritoryID
                              WHERE                  [Group] = 'North America'
                              AND                        a.ModifiedDate BETWEEN  YEAR (2002) AND YEAR (2004)
                              GROUP BY            TotalDue
0
Trying to create a User Defined Function that accepts start and end date, and returns number of sales by card type VISTA between the dates a user inputs. I am using a JOIN of two tables
and common column is the CreditCardID

CREATE FUNCTION NumberOfSales
                               ( @Startdate datetime, @EndDate datetime,@SalesCount INT )
                              RETURNS TABLE
                              AS
                            RETURN
                            (
                                    SELECT                  
                                    @SalesCount =            CardType, COUNT (*) AS CountOfSales
                                          FROM                        AdventureWorks2016.Sales.SalesOrderHeader a
                                          INNER JOIN                  AdventureWorks2016.Sales.CreditCard      b
                                          ON                              a.CreditCardID = b.CreditCardID
                                          WHERE                        CardType = 'Vista'
                                          AND                              b.ModifiedDate BETWEEN '2007/10/01' AND '2013/10/31'
                                    )
                              --Verify Function

                              SELECT * FROM NumberOfSales('2007/10/10','2013/10/19')
      
Msg 102, Level 15, State 1, Procedure NumberOfSales, Line 9 [Batch Start Line 135]
Incorrect syntax near '='.
0
Hello,

Using SQL Server 2012.

I have an xml held by a variable called Variables.  How can i empty every node?  i.e. set it to nil or clear it.

declare @Variables xml = 
'<Variables xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <UserId>1</UserId>
  <UserFirstName xsi:nil="true" ></UserFirstName>
  <UserLastName>Administratör</UserLastName>
  <UserHSAIdentity xsi:nil="true" ></UserHSAIdentity>
  <UserUserId>2Admin</UserUserId>
  <UserEmailAddress1>xx@Skane.se</UserEmailAddress1>
  <UserEmailAddress2 xsi:nil="true" ></UserEmailAddress2>
  <UserAdressRad1>e</UserAdressRad1>
  <UserAdressRad2 xsi:nil="true" ></UserAdressRad2>
  <UserAdressRad3 xsi:nil="true" ></UserAdressRad3>
  <UserPostKod xsi:nil="true" ></UserPostKod>
  <UserPostStad xsi:nil="true" ></UserPostStad>
  <UserTelefon1>12344 129877</UserTelefon1>
  <UserTelefon2 xsi:nil="true" ></UserTelefon2>
  <UserStatus>Inaktiv</UserStatus>
  <UserJobCategory>Övrigt</UserJobCategory>
  <UserChangePasswordDateTime>Aldrig ändrat</UserChangePasswordDateTime>
  <UserLoginTries>0</UserLoginTries>
  <UserLockedDateTime>2018-02-09 14:23</UserLockedDateTime>
  <UserIsGDPRApproved>Nej</UserIsGDPRApproved>
  <UserGDPRApprovalDateTime xsi:nil="true" ></UserGDPRApprovalDateTime>
</Variables>'

Open in new window

0
I am writing a test script.  I need to build a string.  Basically, it will look like this <ID>1</ID>,<ID>2</ID>,<ID>3</ID>,  Below is my sample code but I'm not receiving the expected results.
CREATE TABLE #Temp (
	ID		INT  IDENTITY(1,1) PRIMARY KEY,
    TEST	VARCHAR(20) NOT NULL
);

--DECLARE @IDList TABLE ( ID INT NOT NULL );

INSERT INTO #Temp
(TEST)
VALUES
('Test 1')

DECLARE @Test AS VARCHAR(MAX)

DECLARE @IDENTIFYVALUE VARCHAR(3)

SET @Test = @Test + ('<ID>' + CONVERT(VARCHAR(MAX), (SELECT SCOPE_IDENTITY())) + '</ID>,')
PRINT @Test

INSERT INTO #Temp
(TEST)
VALUES
('Test 2')

SET @Test = @Test + ('<ID>' + CONVERT(VARCHAR(MAX), (SELECT SCOPE_IDENTITY())) + '</ID>,')

INSERT INTO #Temp
(TEST)
VALUES
('Test 3')

SET @Test = @Test + ('<ID>' + CONVERT(VARCHAR(MAX), (SELECT SCOPE_IDENTITY())) + '</ID>,')

PRINT @Test

DROP TABLE #Temp

Open in new window

0
I hope this is a little clearer than mud ;-)

We are going to break out some tables from our Transaction DB and put into another DB for performance reasons, I'll call it Batch DB. This will include moving a lot of procedures to the new Batch DB. Due to having to maintain certain security requirements, we cannot do actual cross-DB operations on the other DB.

My dilemma begins because one of the tables that we are not moving has to remain in the Transaction DB, I'll call it Transaction, and we must update this table after we run a proc on the new Batch DB, this update will be run in our back-end code.

Now the proc on the Batch DB removes records and the IDs of the removed records are needing to be input for the update to the Transaction table on the Transaction DB. These IDs are kept in sync through the back-end code that actually inserts the records in both tables.

We've thought about using JSON or XML but the NVARCHAR(MAX) limit is 4,000 chars and we may have up to 5,000 ID's, TransactionID (PK, int, NOT NULL).

We will get the list of IDs deleted from the Batch DB proc in our back-end code and then we need a way to pass them to a stored proc on the Transaction DB that will update the Transaction table. Anyone know of a way to do that?
0
Here is some sample data from a sql server 2014 table named MemberInfo

Id       chapter    MemberType
11019     cook         M
11342      cook         M      
24468      cook         FM
202550     Cook       FM
7915         Lake         FM
9999         Macon      NM

CREATE TABLE [dbo].[MemberInfo](
      [id] [varchar](10) NOT NULL,
      [Chapter] [varchar](15) NOT NULL,
      [MemberType] [varchar](5) NOT NULL
)


GO
INSERT [dbo].[MemberInfo] ([id], [Chapter], [MemberType]) VALUES (N'11019', N'COOK', N'M')
GO
INSERT [dbo].[MemberInfo] ([id], [Chapter], [MemberType]) VALUES (N'11342', N'COOK', N'M')
GO
INSERT [dbo].[MemberInfo] ([id], [Chapter], [MemberType]) VALUES (N'24468', N'COOK', N'FM')
GO
INSERT [dbo].[MemberInfo] ([id], [Chapter], [MemberType]) VALUES (N'7915', N'LAKE', N'FM')
GO
INSERT [dbo].[MemberInfo] ([id], [Chapter], [MemberType]) VALUES (N'202550', N'COOK', N'FM')
GO
INSERT [dbo].[MemberInfo] ([id], [Chapter], [MemberType]) VALUES (N'9999', N'Macon', N'NM')

Trying to write query that will display list of total Member type by chapter along with total number of id’s
(There are 3 member types M,FM, NM and need 0 if member type does not exist in chapter)

Given above sample data

Looking for following output

Chapter   MemberType_M_Total     MemberType_FM_Total   MemberType_NM_Total       ID_Total
Cook         2                                            2                                                            0                                …
0
I've been looking at examples on how to changes rows into columns and still can't get this:

1. This is an example

CREATE table #final2
(
 whatmonth VARCHAR(10),
 
  col decimal
)

INSERT INTO #final2
(
    whatmonth,
    col
)
SELECT 'July',194


INSERT INTO #final2
(
    whatmonth,
    col
)
SELECT 'June',123

INSERT INTO #final2
(
    whatmonth,
    col
)
SELECT 'total',317

SELECT * FROM #final2

Open in new window


I want it  to be:

total    June   July
317     123   194


I was playing around with this example. I actually want it to be dynamic because I don't know how many rows there will be:

      
select *
from 
(
  select whatmonth, col
  from #final2
) src
pivot
(
  sum(col)
  for whatmonth in ([1],[2],[3])
) piv;

Open in new window

0
Need assistance with sql statement to return the full date to just the Jan 2019, etc.

I need to return a count of ServiceID per SubIssued, for each MonthYear.

Please modify the following query to return the correct results:

 Code:

select       [VSTS_Common_ProjectSubIssue] as 'ProjectSubIssue'
    , Count([System_ID]) AS MTHLYCT
      , VSTS_Common_ResolvedDate
      , CONVERT(VARCHAR(2),MONTH(VSTS_Common_ResolvedDate)) + CONVERT(VARCHAR(4),YEAR(VSTS_Common_ResolvedDate) AS ResolvedDate  
--, REPLACE(RIGHT(CONVERT(VARCHAR(9), VSTS_Common_ResolvedDate(), 6), 6), ' ', '') AS [MMYY]
FROM [qry1].[view1] TFS
where VSTS_Common_ProjectSubIssue
      in
      (
            'China Special Handling Request'
            , 'Empty Box Received'
            , 'Incorrect Product Received'
            , 'Lost in Transit'
            , 'Replacement SN Verification Request'
            , 'Tamper/Damage Bypass Request'
            , 'Tamper/Damaged Product Received'
            , 'Wrong Item Received'
            , 'SN Dosent Match Ticket'
      )
and
[VSTS_Common_InputPath] = 'Service Center'
and System_State in ('Closed', 'Resolved')
and VSTS_Common_ResolvedDate >= '07/01/2019'  
group by VSTS_Common_ProjectSubIssue, VSTS_Common_ResolvedDate
--, Count([System_ID])
--, CONVERT(VARCHAR(2),MONTH(TransactionDte)) + '/' + CONVERT(VARCHAR(4),YEAR(TransactionDte)
0
I am trying to extract data from AX to use in another system. I need Invoice cost by line but can't see where to get it.

INVENTITEMPRICE table has the costs in I need but I don't know how to match the dates to get the correct cost. E.g. if a sale is done after 01/01/2018 and before 26/04/2018 then the correct cost is 15.72 (See below)

Screenshot of INVENTITEMPRICE table
All I'm trying to do is get a cost price per invoice line but I'm not familiar with the AX data structure, can anyone help?
0
Starting with Angular 5
LVL 13
Starting with Angular 5

Learn the essential features and functions of the popular JavaScript framework for building mobile, desktop and web applications.

Hi,
I have a table with a surname column, a sample of which is below.


O REGAN
O SULLIVAN
O MAHONY
O SULLIVAN

I need to update all the names like the values below with an apostrophe (see below)

O’ REGAN
O’ SULLIVAN
O’MAHONY
O’ SULLIVAN


I can find all the relevant values needing updating using
WHERE LTRIM(em_employee_surname) like 'O %'

Open in new window


I need some guidance re the UPDATE statement
Thank you
1
Can you please tell me why this routine is not showing values in the text box when i click in the text area?
screenshot.JPG
      private void listBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            ListBox i = sender as ListBox;
            if (i.SelectedIndex != -1)
            {
                listBox1.SelectedIndex = i.SelectedIndex;
                listBox2.SelectedIndex = i.SelectedIndex;
                txtID.Text = listBox1.SelectedItem.ToString();
                txtName.Text = listBox2.SelectedItem.ToString();               
            }
        
        }

Open in new window

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace InsertUpdateDel
{
    public partial class Form1 : Form
    {
        SqlConnection cn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Lenovo\Documents\Visual Studio 2012\Projects\InsertUpdateDel\InsertUpdateDel\Database1.mdf;Integrated Security=True;User Instance=True");
        SqlCommand cmd = new SqlCommand();
        SqlDataReader sd;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
                cmd.Connection = cn;
                loadlist();
        }

        private void button1_Click(object sender, 

Open in new window

0
Am creating a TEMP TABLE using a GROUP BY  and HAVING CLAUSE.   I must admit this concept has not Sunk in me when how and why,  simple query to retrieve Females who made more that 30,000

            CREATE TABLE #EuroCustomers(CustName            VARCHAR(50),
                                                      Gender                  VARCHAR(50),
                                                      CustHireDate      DATETIME,
                                                      CustSales            MONEY,
                                                      )      
            INSERT INTO #EuroCustomers      
            SELECT            *
            FROM            dbo.EuroCustomers
            WHERE            Gender = 'F'
            GROUP BY      Gender
            HAVING            CustSales > 30000

ERROR Column 'dbo.EuroCustomers.CustSales' is invalid in the HAVING clause because it is not contained in either an aggregate function or the GROUP BY clause.
0
There's a field in a table of a SQL Server database that doesn't except "NULL" but has a default value of "0".  The InsertCommand for the data adapter that vb.net automatically  generates doesn't accommodate this. If the field is left blank in the front end program, the update method of the data adapter fails with a message that the field can't be left blank.  It doesn't set it to the default value that is set in the SQL Server table.  What is the easiest way to get the data adapter to set the field to the default value when the corresponding parameter is null (from being left blank by the user)?
0
Can you please help me in that error?
screenshot.JPG
namespace InsertUpdateDel
{
    partial class Form1
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.label1 = new System.Windows.Forms.Label();
            this.label2 = new System.Windows.Forms.Label();
            this.txtID = new System.Windows.Forms.TextBox();
            this.txtName = new System.Windows.Forms.TextBox();
            this.button1 = new System.Windows.Forms.Button();
            this.listBox2 = new System.Windows.Forms.ListBox();
            this.label3 = new System.Windows.Forms.Label();
            this.label4 = new System.Windows.Forms.Label();
            

Open in new window

0
I am creating a stored procedure.  I will be passing in a string parameter of ID's.  How do I write my SQL code to select those ID's.  

Error I'm getting is:
Msg 245, Level 16, State 1, Line 9
Conversion failed when converting the varchar value '26395, 26396' to data type int.

Here is the code:
DECLARE @POID AS VARCHAR(200) = '26395, 26396'

SELECT * FROM PO WHERE POID IN (@POID)

Open in new window

0
In the following query I have two calculated columns SlotTime and SlotBreak and I wish to subtract them to create SlotWorked but SQL Server claims SlotTime and SlotBreak are invalid column names
select R.site_id,L.Activity,L.PT,L.Rate,'1/' + DateName(month,R.week_commencing) + '/' + Cast(Year(R.week_commencing) as varchar) as FDM,
L.D1AB AS DayAbs,
L.D1F-L.D1S as SlotTime,
Case when L.D1F-L.D1S < 6.02/24 then 0 else 0.5/24 end as SlotBreak,
([SlotTime]-[SlotBreak]) as SlotWorked
from
tblRotas R inner join tblRotaLines L on R.Rota_ID=L.rota_id
0
Can you please help me in that error?
Error in List Box[code]
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace InsertUpdateDel
{
    public partial class Form1 : Form
    {
        SqlConnection cn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Lenovo\Documents\Visual Studio 2012\Projects\InsertUpdateDel\InsertUpdateDel\Database1.mdf;Integrated Security=True;User Instance=True");
        SqlCommand cmd = new SqlCommand();
        SqlDataReader sd;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
                cmd.Connection = cn;
                loadlist();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (txtID.Text != "" & txtName.Text != "")
            {
                cn.Open();
                cmd.CommandText = "Insert into info(id, name) values ('" +txtID.Text+"', '" +txtName.Text+"')";
                cmd.ExecuteNonQuery();
                cmd.Clone();
                MessageBox.Show("Record Inserted", "Programming");
                cn.Close();
                txtID.Text="";
                txtName.Text="";
                loadlist();
            }
        }
        …
0
Can you please tell me what this error means?

Error statement: sd = cmd.ExecuteReader();

screenshot.JPG
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace InsertUpdateDel
{
    public partial class Form1 : Form
    {
        SqlConnection cn = new SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Lenovo\Documents\Visual Studio 2012\Projects\InsertUpdateDel\InsertUpdateDel\Database1.mdf;Integrated Security=True;User Instance=True");
        SqlCommand cmd = new SqlCommand();
        SqlDataAdapter sd;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
                cmd.Connection = cn;
                loadlist();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (txtID.Text != "" & txtName.Text != "")
            {
                cn.Open();
                cmd.CommandText = "Insert into info(id, name) values ('" +txtID.Text+"', '" +txtName.Text+"')";
                cmd.ExecuteNonQuery();
                cmd.Clone();
                MessageBox.Show("Record Inserted", "Programming");
                cn.Close();
                txtID.Text="";
                txtName.Text="";
                loadlist();
            }
        }

Open in new window

0
Ensure you’re charging the right price for your IT
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

I have three fields that define the relationship a person has to a particular incident.
table Fields:
Field1
Field2
Field3  

MS SQL

 What I want to do is display the values in these fields with a '-' separating them.  Not all fields need to be filled in so I don't want the display to show extra '-'
example:
Family - Brother - Younger   ///  When all three fields are filled in
Family - Brother-                    /// When only first two fields are filled in.  Trailing '-' should be removed.
Family --                                   /// When only first field is filled in.  Trailing '-'s should be removed.
- Brother - Younger                /// When only fields two and three are filled in.  (There currently is no restriction on leaving the first field blank and using the other two but its not
                                                        recommended,   So in this case I would want the first '-' removed and only display Brother - Younger.

What would be the best way to go about doing this.   I can use this in several other record types so should this be a sp or function?
0
I have a staging table that I want to loop through and insert into the production table - the thing is in the stage table there is multiple fields that might have data, and if they have data I want to insert a new row into production with certain fields in the staging table.

For example in stage table - Customer ID, Customer Name, Order Number 1, Order Number 2, Order Number 3, Created Date, Created By

In the Production Table I want to insert into these fields  Customer ID, Customer ID, Customer Name, Order Number, Created Date, Create By

So if Order Number 1 has a value it inserts 1 row into production, if Order Number 2 has a value insert another row and if Order Number 3 has a value insert one more row.

So the end goal is to split the 1 row in staging into possibly 3 rows if all 3 Order Number fields has value.

Is this possible and if so how ?

Thanks
0
I am creating a Temporary table, How can I define the values in the columns. I want to use the Sum/Count aggregate functions and use GROUP BY STATEMENT ?

CREATE      TABLE      #ProductionInFo      (ProductID, COUNT(*) ProductCount,SUM(LineTotal) TotalSales)
                                          
            
            INSERT INTO            #ProductionInFo
            SELECT                  ProductID, COUNT(*) ProductCount,SUM(LineTotal) TotalSales
            FROM                  Sales.SalesOrderDetail
                                    GROUP BY      ProductID
                                    Order by      ProductID
SELECT *  FROM #ProductionInfo


                  SELECT            ProductID, COUNT(*) ProductCount,SUM(LineTotal) TotalSales
                  FROM            Sales.SalesOrderDetail
                                    GROUP BY      ProductID
                                    Order by      ProductID
0
Experts I'm going resubmit a too question on Change Tracking with fresh data


The table structure I'm working with is as follows:

CREATE TABLE PrestigeCars.dbo.data_source_table (
  PersonID INT NOT NULL
 ,Name VARCHAR(255) NULL
 ,Age INT NULL
 ,PRIMARY KEY CLUSTERED (PersonID)
) ON [PRIMARY]
GO

Open in new window


ALTER TABLE dbo.data_source_table
ENABLE CHANGE_TRACKING WITH (TRACK_COLUMNS_UPDATED = ON)
GO

Open in new window



Before doing any modifications to the dataset it looks as follows

org
The actual dataset is as follows:

create table data_source_table
(
    PersonID int NOT NULL,
    Name varchar(255),
    Age int
    PRIMARY KEY (PersonID)
);

INSERT INTO data_source_table
    (PersonID, Name, Age)
VALUES
    (1, 'aaaa', 21),
    (2, 'bbbb', 24),
    (3, 'cccc', 20),
    (4, 'dddd', 26),
    (5, 'eeee', 22);

Open in new window



Now, I have modified the dataset as follows:

mod
From the above you can see I have inserted a row 'InsertedCol', I have updated a row at PersonID 5 'eeee-updatedCol', and I have deleted a row at PersonID 4 'dddd'.

dfa
I have then executed the following code:

 
SELECT
    ChVer = SYS_CHANGE_VERSION,
    ChCrVer = SYS_CHANGE_CREATION_VERSION,
    ChOp = SYS_CHANGE_OPERATION, PA.*
  FROM CHANGETABLE(CHANGES dbo.data_source_table, 29) AS ChTbl
 LEFT JOIN dbo.data_source_table PA ON PA.PersonID = ChTbl.PersonID
And the results are as follows:

Open in new window




You can see everything is working fine, but where it should say 'dddd' in the name column is gives the results (null).

I need 'dddd' where the null is.

Can you help me with that?
0
Hi EE,

Using the following tutorial for visual guidance:

https://www.mssqltips.com/sqlservertutorial/203/simple-way-to-import-data-into-sql-server/

I am trying to import some data into an table. One excel tab allowed me to import the data with no hassles the other excel table gives me the error message Error: 0xC002F210  the table already exists.

The table already existed previously and I don't have create permissions against the database when I did the first import what is going on?

Any assistance is welcome.

Cheers
0
Am creating a CTE table RatingInfo, I am getting this error invalid error

(2 rows affected)
Msg 208, Level 16, State 1, Line 100
Invalid object name 'RatingInfo'.

            ---                  CREATING A CTE STRUCTURE

            WITH            RatingInfo      (ReviewerName,EmailAddress,Rating,ReviewDate)
            AS
            --We Define the CTE query
            (
                        SELECT            ReviewerName,
                                          EmailAddress,
                                          Rating,
                                          ReviewDate
                        FROM            Production.ProductReview
                        
            )
            --Define the Outer query referencing CTE_RatingInfo
            
                  (      SELECT            ReviewerName,
                                          EmailAddress,
                                          Rating,
                                          ReviewDate
                        FROM            RatingInfo

                        WHERE            Rating  BETWEEN 2 AND 5
                        AND                  EmailAddress like 'J%'
                  )

            

            SELECT *      FROM      RatingInfo
0

Microsoft SQL Server

164K

Solutions

50K

Contributors

Microsoft SQL Server is a suite of relational database management system (RDBMS) products providing multi-user database access functionality.SQL Server is available in multiple versions, typically identified by release year, and versions are subdivided into editions to distinguish between product functionality. Component services include integration (SSIS), reporting (SSRS), analysis (SSAS), data quality, master data, T-SQL and performance tuning.