Is there an optimal way to create logical columns from physical column using SQL query statement?SQL Query Help: Transforming Dates In A Non-Trivial WaySQL exclude a column using SELECT * [except columnA] FROM tableA?What is the best way to auto-generate INSERT statements for a SQL Server table?How can I get column names from a table in SQL Server?SQL queries in Case statementHow do I add a column derived from a select statement within a select statement?SQL Server, Select from dateadd of existing date variableSelect multiple columns from a subquery in SQL Serverasp.net chart read from aspx.cs file with custom query from sql serverMS SQL Server finding top 4 peak readings in a table and display as columns

How do I address my Catering staff subordinate seen eating from a chafing dish before the customers?

Is it normal practice to screen share with a client?

What does コテッと mean?

3D Statue Park: U shapes

How acidic does a mixture have to be for milk to curdle?

Why are off grid solar setups only 12, 24, 48 VDC?

What does "see" in "the Holy See" mean?

Invert Some Switches on a Switchboard

Trapped in an ocean Temple in Minecraft?

A planet illuminated by a black hole?

Convert every file from JPEG to GIF in terminal

What is the meaning of "you has the wind of me"?

How can I receive packages while in France?

Did the IBM PC use the 8088's NMI line?

Drillers for petroleum strike gusher of blood

How can I prevent corporations from growing their own workforce?

Binomial analogue of Riemann sum for definite integral

Trying to build a function to compute divided difference for arbitrary list of points

kids pooling money for Lego League and taxes

How do I run a game when my PCs have different approaches to combat?

How to deal with a player who makes bad characters and kills them?

What is the effect and/or good reasons of changing a paper bill to a coin?

What to do when you reach a conclusion and find out later on that someone else already did?

Giant space birds hatching out of planets; short story



Is there an optimal way to create logical columns from physical column using SQL query statement?


SQL Query Help: Transforming Dates In A Non-Trivial WaySQL exclude a column using SELECT * [except columnA] FROM tableA?What is the best way to auto-generate INSERT statements for a SQL Server table?How can I get column names from a table in SQL Server?SQL queries in Case statementHow do I add a column derived from a select statement within a select statement?SQL Server, Select from dateadd of existing date variableSelect multiple columns from a subquery in SQL Serverasp.net chart read from aspx.cs file with custom query from sql serverMS SQL Server finding top 4 peak readings in a table and display as columns






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I'm writing a SQL query using a table. My requirement is that I need to generate two logical columns from one physical column with certain conditions. In SQL how to generate two logical columns in final result set?



I have so far tried using sub-queries to derive those logical columns. But that sub-query returns error when incorporate it as a column in main query.



Overall there are other tables which will be joined using SQL JOIN to derive respective columns.



Columns:



  1. CarrierName NVARCHAR(10)

  2. MonthDate DATETIME

  3. Stage INT

Scenario:

In my SQL Server table there is a column called Stage of type int that contains values like 1, 2, 3, 4.



Now, I have two date criteria to apply on above column to derive two logical columns in final result set.



Criteria #1:



Get carriers from past 12 months and priors to past month end date and value of "CurrentStage" should be less than and derive "PriorStage"



Example:



Current month is: March 2019 (2019-03-25) or any given date
Past latest month end date would be: 2019-02-28



12 months prior to above past latest month would be:
From 2018-02-01 To 2019-01-31



Criteria #2:



Get Carriers from past latest month end date and derive "CurrentStage"



While writing two independent SQL SELECT statements I get my desired results.
My challenge is when I think them to integrate in one select statement.



I get this error:




Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression




Code:



DECLARE @DATE DATETIME
SET @DATE = '2018-08-25';

--QUERY 1 - RECORDS WITH PREVIOUS MONTH END DATE
SELECT
T1.CarrierName AS 'Carrier_Number',
T1.Stage AS 'Monitoring_Stage–Current'
FROM
table1 T1
WHERE
T1.Stage IS NOT NULL AND
CONVERT(DATE, T1.MonthDate) = CONVERT(DATE, DATEADD(D, -(DAY(@DATE)), @DATE))

--QUERY 2 - RECORDS FROM PAST 12 MONTHS PRIOR PREVIOUS MONTH END DATE
SELECT
T2.CarrierName,
T2.Stage AS 'Monitoring_Stage–Prior'
FROM
table2 T2
WHERE
T2.Stage IS NOT NULL AND
CONVERT(DATE, T2.MonthDate) BETWEEN CONVERT(DATE, DATEADD(M, -12, DATEADD(D, -(DAY(@DATE)), @DATE)))
AND CONVERT(DATE, DATEADD(D, -(DAY(@DATE) + (DAY(DATEADD(D, -(DAY(@DATE)), @DATE)))), @DATE))
AND T2.Stage) > (SELECT DISTINCT MAX(m.Stage AS INT))
FROM table1 m
WHERE CONVERT(DATE, m.MonthDate) = CONVERT(DATE, DATEADD(D, -(DAY(@DATE)), @DATE))
AND T2.CarrierName = m.CarrierName)


My final expected result set should contain below columns.
Where CurrentStage value is less than PriorStage value.



Expected Results



CarrierName | CurrentStage | PriorStage
--------------+--------------+-------------
C11122 | 1 | 2
C32233 | 3 | 4


Actual Result



I am looking for alternatives. I.e. CTE, Union, temp table etc.



Something like:



SELECT 
CarrierName,
Query 1 Result As 'CurrentStage',
Query 2 Result As 'PrioreStage'
FROM
table1


To improve this post, I am adding my response here. My resolution below for this posted question is still under evaluation hence not posting it as my final answer. But it really brought a light to my effort.



RESOLUTION:



SELECT 
DISTINCT M.CarrierName, A.[CurrentStage], B.[PriorStage]
FROM
--QUERY 1 - RECORDS WITH CURRENT MONTH END DATE
(SELECT M.CarrierName, M.CarrierID
, Stage AS 'CurrentStage'
FROM table1 M
WHERE M.Stage IS NOT NULL AND
CONVERT(date, M.MonthDate) = CONVERT(date, DATEADD(D,-(DAY(@DATE)), @DATE))
)
A **inner join**
(
--QUERY 2 - RECORDS FROM PAST 12 MONTHS PRIOR CURRENT MONTH END DATE
SELECT M2.CarrierName, M2.CarrierID
, Stage AS 'PriorStage'
FROM table1 M2
WHERE M2.Stage IS NOT NULL AND
CONVERT(date, M2.MonthDate) BETWEEN CONVERT(date, DATEADD(M, -12, DATEADD(D,-(DAY(@DATE)), @DATE)))
AND CONVERT(date, DATEADD(D,-(DAY(@DATE)+(DAY(DATEADD(D,-(DAY(@DATE)), @DATE)))), @DATE))
AND M2.Stage > (SELECT DISTINCT max(m.Stage)
FROM table1 m
WHERE CONVERT(date, m.MonthDate) = CONVERT(date, DATEADD(D,-(DAY(@DATE)), @DATE)) AND
M2.CarrierName = m.CarrierName
)

) B on b.Carrier_Number = a.Carrier_Number
INNER JOIN table1 M ON A.CarrierID = M.CarrierID AND B.CarrierID = M.CarrierID









share|improve this question
























  • Not enough information to help you. You show us the code of the separate statements that work. You say you get an error when you try to integrate them in a single select, but you don't show us the code that generates the error. There is no way we can see what you are doing wrong to get the error, or suggest how it can be fixed.

    – Tab Alleman
    Mar 26 at 18:07











  • I understand @TabAlleman. But the query which was throwing error was somehow not in a shape I could post. Sometimes when problem is not so generic it is little annoying and weird to decipher or reproduce. But hatsoff to StackOverflow that soon after posting this issue, I was provided with not exact solution but a way which at least took me little closer to the result set how I wanted it. I updated my question with resolution. Just not posted it as I am still evaluating with various data that I have. Thanks for showing up though! I appreciate it.

    – Binoy
    Mar 26 at 18:40

















0















I'm writing a SQL query using a table. My requirement is that I need to generate two logical columns from one physical column with certain conditions. In SQL how to generate two logical columns in final result set?



I have so far tried using sub-queries to derive those logical columns. But that sub-query returns error when incorporate it as a column in main query.



Overall there are other tables which will be joined using SQL JOIN to derive respective columns.



Columns:



  1. CarrierName NVARCHAR(10)

  2. MonthDate DATETIME

  3. Stage INT

Scenario:

In my SQL Server table there is a column called Stage of type int that contains values like 1, 2, 3, 4.



Now, I have two date criteria to apply on above column to derive two logical columns in final result set.



Criteria #1:



Get carriers from past 12 months and priors to past month end date and value of "CurrentStage" should be less than and derive "PriorStage"



Example:



Current month is: March 2019 (2019-03-25) or any given date
Past latest month end date would be: 2019-02-28



12 months prior to above past latest month would be:
From 2018-02-01 To 2019-01-31



Criteria #2:



Get Carriers from past latest month end date and derive "CurrentStage"



While writing two independent SQL SELECT statements I get my desired results.
My challenge is when I think them to integrate in one select statement.



I get this error:




Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression




Code:



DECLARE @DATE DATETIME
SET @DATE = '2018-08-25';

--QUERY 1 - RECORDS WITH PREVIOUS MONTH END DATE
SELECT
T1.CarrierName AS 'Carrier_Number',
T1.Stage AS 'Monitoring_Stage–Current'
FROM
table1 T1
WHERE
T1.Stage IS NOT NULL AND
CONVERT(DATE, T1.MonthDate) = CONVERT(DATE, DATEADD(D, -(DAY(@DATE)), @DATE))

--QUERY 2 - RECORDS FROM PAST 12 MONTHS PRIOR PREVIOUS MONTH END DATE
SELECT
T2.CarrierName,
T2.Stage AS 'Monitoring_Stage–Prior'
FROM
table2 T2
WHERE
T2.Stage IS NOT NULL AND
CONVERT(DATE, T2.MonthDate) BETWEEN CONVERT(DATE, DATEADD(M, -12, DATEADD(D, -(DAY(@DATE)), @DATE)))
AND CONVERT(DATE, DATEADD(D, -(DAY(@DATE) + (DAY(DATEADD(D, -(DAY(@DATE)), @DATE)))), @DATE))
AND T2.Stage) > (SELECT DISTINCT MAX(m.Stage AS INT))
FROM table1 m
WHERE CONVERT(DATE, m.MonthDate) = CONVERT(DATE, DATEADD(D, -(DAY(@DATE)), @DATE))
AND T2.CarrierName = m.CarrierName)


My final expected result set should contain below columns.
Where CurrentStage value is less than PriorStage value.



Expected Results



CarrierName | CurrentStage | PriorStage
--------------+--------------+-------------
C11122 | 1 | 2
C32233 | 3 | 4


Actual Result



I am looking for alternatives. I.e. CTE, Union, temp table etc.



Something like:



SELECT 
CarrierName,
Query 1 Result As 'CurrentStage',
Query 2 Result As 'PrioreStage'
FROM
table1


To improve this post, I am adding my response here. My resolution below for this posted question is still under evaluation hence not posting it as my final answer. But it really brought a light to my effort.



RESOLUTION:



SELECT 
DISTINCT M.CarrierName, A.[CurrentStage], B.[PriorStage]
FROM
--QUERY 1 - RECORDS WITH CURRENT MONTH END DATE
(SELECT M.CarrierName, M.CarrierID
, Stage AS 'CurrentStage'
FROM table1 M
WHERE M.Stage IS NOT NULL AND
CONVERT(date, M.MonthDate) = CONVERT(date, DATEADD(D,-(DAY(@DATE)), @DATE))
)
A **inner join**
(
--QUERY 2 - RECORDS FROM PAST 12 MONTHS PRIOR CURRENT MONTH END DATE
SELECT M2.CarrierName, M2.CarrierID
, Stage AS 'PriorStage'
FROM table1 M2
WHERE M2.Stage IS NOT NULL AND
CONVERT(date, M2.MonthDate) BETWEEN CONVERT(date, DATEADD(M, -12, DATEADD(D,-(DAY(@DATE)), @DATE)))
AND CONVERT(date, DATEADD(D,-(DAY(@DATE)+(DAY(DATEADD(D,-(DAY(@DATE)), @DATE)))), @DATE))
AND M2.Stage > (SELECT DISTINCT max(m.Stage)
FROM table1 m
WHERE CONVERT(date, m.MonthDate) = CONVERT(date, DATEADD(D,-(DAY(@DATE)), @DATE)) AND
M2.CarrierName = m.CarrierName
)

) B on b.Carrier_Number = a.Carrier_Number
INNER JOIN table1 M ON A.CarrierID = M.CarrierID AND B.CarrierID = M.CarrierID









share|improve this question
























  • Not enough information to help you. You show us the code of the separate statements that work. You say you get an error when you try to integrate them in a single select, but you don't show us the code that generates the error. There is no way we can see what you are doing wrong to get the error, or suggest how it can be fixed.

    – Tab Alleman
    Mar 26 at 18:07











  • I understand @TabAlleman. But the query which was throwing error was somehow not in a shape I could post. Sometimes when problem is not so generic it is little annoying and weird to decipher or reproduce. But hatsoff to StackOverflow that soon after posting this issue, I was provided with not exact solution but a way which at least took me little closer to the result set how I wanted it. I updated my question with resolution. Just not posted it as I am still evaluating with various data that I have. Thanks for showing up though! I appreciate it.

    – Binoy
    Mar 26 at 18:40













0












0








0








I'm writing a SQL query using a table. My requirement is that I need to generate two logical columns from one physical column with certain conditions. In SQL how to generate two logical columns in final result set?



I have so far tried using sub-queries to derive those logical columns. But that sub-query returns error when incorporate it as a column in main query.



Overall there are other tables which will be joined using SQL JOIN to derive respective columns.



Columns:



  1. CarrierName NVARCHAR(10)

  2. MonthDate DATETIME

  3. Stage INT

Scenario:

In my SQL Server table there is a column called Stage of type int that contains values like 1, 2, 3, 4.



Now, I have two date criteria to apply on above column to derive two logical columns in final result set.



Criteria #1:



Get carriers from past 12 months and priors to past month end date and value of "CurrentStage" should be less than and derive "PriorStage"



Example:



Current month is: March 2019 (2019-03-25) or any given date
Past latest month end date would be: 2019-02-28



12 months prior to above past latest month would be:
From 2018-02-01 To 2019-01-31



Criteria #2:



Get Carriers from past latest month end date and derive "CurrentStage"



While writing two independent SQL SELECT statements I get my desired results.
My challenge is when I think them to integrate in one select statement.



I get this error:




Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression




Code:



DECLARE @DATE DATETIME
SET @DATE = '2018-08-25';

--QUERY 1 - RECORDS WITH PREVIOUS MONTH END DATE
SELECT
T1.CarrierName AS 'Carrier_Number',
T1.Stage AS 'Monitoring_Stage–Current'
FROM
table1 T1
WHERE
T1.Stage IS NOT NULL AND
CONVERT(DATE, T1.MonthDate) = CONVERT(DATE, DATEADD(D, -(DAY(@DATE)), @DATE))

--QUERY 2 - RECORDS FROM PAST 12 MONTHS PRIOR PREVIOUS MONTH END DATE
SELECT
T2.CarrierName,
T2.Stage AS 'Monitoring_Stage–Prior'
FROM
table2 T2
WHERE
T2.Stage IS NOT NULL AND
CONVERT(DATE, T2.MonthDate) BETWEEN CONVERT(DATE, DATEADD(M, -12, DATEADD(D, -(DAY(@DATE)), @DATE)))
AND CONVERT(DATE, DATEADD(D, -(DAY(@DATE) + (DAY(DATEADD(D, -(DAY(@DATE)), @DATE)))), @DATE))
AND T2.Stage) > (SELECT DISTINCT MAX(m.Stage AS INT))
FROM table1 m
WHERE CONVERT(DATE, m.MonthDate) = CONVERT(DATE, DATEADD(D, -(DAY(@DATE)), @DATE))
AND T2.CarrierName = m.CarrierName)


My final expected result set should contain below columns.
Where CurrentStage value is less than PriorStage value.



Expected Results



CarrierName | CurrentStage | PriorStage
--------------+--------------+-------------
C11122 | 1 | 2
C32233 | 3 | 4


Actual Result



I am looking for alternatives. I.e. CTE, Union, temp table etc.



Something like:



SELECT 
CarrierName,
Query 1 Result As 'CurrentStage',
Query 2 Result As 'PrioreStage'
FROM
table1


To improve this post, I am adding my response here. My resolution below for this posted question is still under evaluation hence not posting it as my final answer. But it really brought a light to my effort.



RESOLUTION:



SELECT 
DISTINCT M.CarrierName, A.[CurrentStage], B.[PriorStage]
FROM
--QUERY 1 - RECORDS WITH CURRENT MONTH END DATE
(SELECT M.CarrierName, M.CarrierID
, Stage AS 'CurrentStage'
FROM table1 M
WHERE M.Stage IS NOT NULL AND
CONVERT(date, M.MonthDate) = CONVERT(date, DATEADD(D,-(DAY(@DATE)), @DATE))
)
A **inner join**
(
--QUERY 2 - RECORDS FROM PAST 12 MONTHS PRIOR CURRENT MONTH END DATE
SELECT M2.CarrierName, M2.CarrierID
, Stage AS 'PriorStage'
FROM table1 M2
WHERE M2.Stage IS NOT NULL AND
CONVERT(date, M2.MonthDate) BETWEEN CONVERT(date, DATEADD(M, -12, DATEADD(D,-(DAY(@DATE)), @DATE)))
AND CONVERT(date, DATEADD(D,-(DAY(@DATE)+(DAY(DATEADD(D,-(DAY(@DATE)), @DATE)))), @DATE))
AND M2.Stage > (SELECT DISTINCT max(m.Stage)
FROM table1 m
WHERE CONVERT(date, m.MonthDate) = CONVERT(date, DATEADD(D,-(DAY(@DATE)), @DATE)) AND
M2.CarrierName = m.CarrierName
)

) B on b.Carrier_Number = a.Carrier_Number
INNER JOIN table1 M ON A.CarrierID = M.CarrierID AND B.CarrierID = M.CarrierID









share|improve this question
















I'm writing a SQL query using a table. My requirement is that I need to generate two logical columns from one physical column with certain conditions. In SQL how to generate two logical columns in final result set?



I have so far tried using sub-queries to derive those logical columns. But that sub-query returns error when incorporate it as a column in main query.



Overall there are other tables which will be joined using SQL JOIN to derive respective columns.



Columns:



  1. CarrierName NVARCHAR(10)

  2. MonthDate DATETIME

  3. Stage INT

Scenario:

In my SQL Server table there is a column called Stage of type int that contains values like 1, 2, 3, 4.



Now, I have two date criteria to apply on above column to derive two logical columns in final result set.



Criteria #1:



Get carriers from past 12 months and priors to past month end date and value of "CurrentStage" should be less than and derive "PriorStage"



Example:



Current month is: March 2019 (2019-03-25) or any given date
Past latest month end date would be: 2019-02-28



12 months prior to above past latest month would be:
From 2018-02-01 To 2019-01-31



Criteria #2:



Get Carriers from past latest month end date and derive "CurrentStage"



While writing two independent SQL SELECT statements I get my desired results.
My challenge is when I think them to integrate in one select statement.



I get this error:




Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression




Code:



DECLARE @DATE DATETIME
SET @DATE = '2018-08-25';

--QUERY 1 - RECORDS WITH PREVIOUS MONTH END DATE
SELECT
T1.CarrierName AS 'Carrier_Number',
T1.Stage AS 'Monitoring_Stage–Current'
FROM
table1 T1
WHERE
T1.Stage IS NOT NULL AND
CONVERT(DATE, T1.MonthDate) = CONVERT(DATE, DATEADD(D, -(DAY(@DATE)), @DATE))

--QUERY 2 - RECORDS FROM PAST 12 MONTHS PRIOR PREVIOUS MONTH END DATE
SELECT
T2.CarrierName,
T2.Stage AS 'Monitoring_Stage–Prior'
FROM
table2 T2
WHERE
T2.Stage IS NOT NULL AND
CONVERT(DATE, T2.MonthDate) BETWEEN CONVERT(DATE, DATEADD(M, -12, DATEADD(D, -(DAY(@DATE)), @DATE)))
AND CONVERT(DATE, DATEADD(D, -(DAY(@DATE) + (DAY(DATEADD(D, -(DAY(@DATE)), @DATE)))), @DATE))
AND T2.Stage) > (SELECT DISTINCT MAX(m.Stage AS INT))
FROM table1 m
WHERE CONVERT(DATE, m.MonthDate) = CONVERT(DATE, DATEADD(D, -(DAY(@DATE)), @DATE))
AND T2.CarrierName = m.CarrierName)


My final expected result set should contain below columns.
Where CurrentStage value is less than PriorStage value.



Expected Results



CarrierName | CurrentStage | PriorStage
--------------+--------------+-------------
C11122 | 1 | 2
C32233 | 3 | 4


Actual Result



I am looking for alternatives. I.e. CTE, Union, temp table etc.



Something like:



SELECT 
CarrierName,
Query 1 Result As 'CurrentStage',
Query 2 Result As 'PrioreStage'
FROM
table1


To improve this post, I am adding my response here. My resolution below for this posted question is still under evaluation hence not posting it as my final answer. But it really brought a light to my effort.



RESOLUTION:



SELECT 
DISTINCT M.CarrierName, A.[CurrentStage], B.[PriorStage]
FROM
--QUERY 1 - RECORDS WITH CURRENT MONTH END DATE
(SELECT M.CarrierName, M.CarrierID
, Stage AS 'CurrentStage'
FROM table1 M
WHERE M.Stage IS NOT NULL AND
CONVERT(date, M.MonthDate) = CONVERT(date, DATEADD(D,-(DAY(@DATE)), @DATE))
)
A **inner join**
(
--QUERY 2 - RECORDS FROM PAST 12 MONTHS PRIOR CURRENT MONTH END DATE
SELECT M2.CarrierName, M2.CarrierID
, Stage AS 'PriorStage'
FROM table1 M2
WHERE M2.Stage IS NOT NULL AND
CONVERT(date, M2.MonthDate) BETWEEN CONVERT(date, DATEADD(M, -12, DATEADD(D,-(DAY(@DATE)), @DATE)))
AND CONVERT(date, DATEADD(D,-(DAY(@DATE)+(DAY(DATEADD(D,-(DAY(@DATE)), @DATE)))), @DATE))
AND M2.Stage > (SELECT DISTINCT max(m.Stage)
FROM table1 m
WHERE CONVERT(date, m.MonthDate) = CONVERT(date, DATEADD(D,-(DAY(@DATE)), @DATE)) AND
M2.CarrierName = m.CarrierName
)

) B on b.Carrier_Number = a.Carrier_Number
INNER JOIN table1 M ON A.CarrierID = M.CarrierID AND B.CarrierID = M.CarrierID






sql-server subquery






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 26 at 18:36







Binoy

















asked Mar 26 at 17:32









BinoyBinoy

11211 bronze badges




11211 bronze badges












  • Not enough information to help you. You show us the code of the separate statements that work. You say you get an error when you try to integrate them in a single select, but you don't show us the code that generates the error. There is no way we can see what you are doing wrong to get the error, or suggest how it can be fixed.

    – Tab Alleman
    Mar 26 at 18:07











  • I understand @TabAlleman. But the query which was throwing error was somehow not in a shape I could post. Sometimes when problem is not so generic it is little annoying and weird to decipher or reproduce. But hatsoff to StackOverflow that soon after posting this issue, I was provided with not exact solution but a way which at least took me little closer to the result set how I wanted it. I updated my question with resolution. Just not posted it as I am still evaluating with various data that I have. Thanks for showing up though! I appreciate it.

    – Binoy
    Mar 26 at 18:40

















  • Not enough information to help you. You show us the code of the separate statements that work. You say you get an error when you try to integrate them in a single select, but you don't show us the code that generates the error. There is no way we can see what you are doing wrong to get the error, or suggest how it can be fixed.

    – Tab Alleman
    Mar 26 at 18:07











  • I understand @TabAlleman. But the query which was throwing error was somehow not in a shape I could post. Sometimes when problem is not so generic it is little annoying and weird to decipher or reproduce. But hatsoff to StackOverflow that soon after posting this issue, I was provided with not exact solution but a way which at least took me little closer to the result set how I wanted it. I updated my question with resolution. Just not posted it as I am still evaluating with various data that I have. Thanks for showing up though! I appreciate it.

    – Binoy
    Mar 26 at 18:40
















Not enough information to help you. You show us the code of the separate statements that work. You say you get an error when you try to integrate them in a single select, but you don't show us the code that generates the error. There is no way we can see what you are doing wrong to get the error, or suggest how it can be fixed.

– Tab Alleman
Mar 26 at 18:07





Not enough information to help you. You show us the code of the separate statements that work. You say you get an error when you try to integrate them in a single select, but you don't show us the code that generates the error. There is no way we can see what you are doing wrong to get the error, or suggest how it can be fixed.

– Tab Alleman
Mar 26 at 18:07













I understand @TabAlleman. But the query which was throwing error was somehow not in a shape I could post. Sometimes when problem is not so generic it is little annoying and weird to decipher or reproduce. But hatsoff to StackOverflow that soon after posting this issue, I was provided with not exact solution but a way which at least took me little closer to the result set how I wanted it. I updated my question with resolution. Just not posted it as I am still evaluating with various data that I have. Thanks for showing up though! I appreciate it.

– Binoy
Mar 26 at 18:40





I understand @TabAlleman. But the query which was throwing error was somehow not in a shape I could post. Sometimes when problem is not so generic it is little annoying and weird to decipher or reproduce. But hatsoff to StackOverflow that soon after posting this issue, I was provided with not exact solution but a way which at least took me little closer to the result set how I wanted it. I updated my question with resolution. Just not posted it as I am still evaluating with various data that I have. Thanks for showing up though! I appreciate it.

– Binoy
Mar 26 at 18:40












0






active

oldest

votes










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55363095%2fis-there-an-optimal-way-to-create-logical-columns-from-physical-column-using-sql%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes




Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.







Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55363095%2fis-there-an-optimal-way-to-create-logical-columns-from-physical-column-using-sql%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해