Question Update a Query with Case When Data
-
suppose My Query Like Select x.srlNo,x.ProductID from (Select Srlno,ProductID,SaleType from SaleDetail)as x where X.Srlno in (Select Y.SrlNo-1 from(Select SrlNo from SaleDetail where SaleType=5) as Y) "It is Just One Row value I am Specify, Actually it is generate Dynamicaly" How Can I Modifying my field through Case When. I want to Modify some field of the Current Row with the Privious row data in my Query
Arindam Banerjee Sr. Software Developer Rance Computer Pvt Ltd. Kolkata (India)
-
suppose My Query Like Select x.srlNo,x.ProductID from (Select Srlno,ProductID,SaleType from SaleDetail)as x where X.Srlno in (Select Y.SrlNo-1 from(Select SrlNo from SaleDetail where SaleType=5) as Y) "It is Just One Row value I am Specify, Actually it is generate Dynamicaly" How Can I Modifying my field through Case When. I want to Modify some field of the Current Row with the Privious row data in my Query
Arindam Banerjee Sr. Software Developer Rance Computer Pvt Ltd. Kolkata (India)
pdnet wrote:
It is Just One Row value I am Specify, Actually it is generate Dynamicaly" How Can I Modifying my field through Case When
pdnet wrote:
I want to Modify some field of the Current Row with the Privious row data in my Query
If you're using SQL Server, that won't work unless you create a function and store the value from the previous row. Also you may have trouble defining which is the previous row since typically the rows are coming in random order. Perhaps you should write a little example with data, what you're trying to achieve.
The need to optimize rises from a bad design.My articles[^]
-
pdnet wrote:
It is Just One Row value I am Specify, Actually it is generate Dynamicaly" How Can I Modifying my field through Case When
pdnet wrote:
I want to Modify some field of the Current Row with the Privious row data in my Query
If you're using SQL Server, that won't work unless you create a function and store the value from the previous row. Also you may have trouble defining which is the previous row since typically the rows are coming in random order. Perhaps you should write a little example with data, what you're trying to achieve.
The need to optimize rises from a bad design.My articles[^]
Suppose My Data Looks Like : SrlNo Type ProductID Group 1 1 1.0 A 2 1 2.0 B 3 2 3.0 C 4 1 4.0 A I Want to Update This Data in My Query in this way that "If the Type of the Product is 2 then It is Replaced by the Previous Product's Group" That means : SrlNo Type ProductID Group 1 1 1.0 A 2 1 2.0 B 3 2 3.0 B 4 1 4.0 A
Arindam Banerjee Sr. Software Developer Rance Computer Pvt Ltd. Kolkata (India)
-
Suppose My Data Looks Like : SrlNo Type ProductID Group 1 1 1.0 A 2 1 2.0 B 3 2 3.0 C 4 1 4.0 A I Want to Update This Data in My Query in this way that "If the Type of the Product is 2 then It is Replaced by the Previous Product's Group" That means : SrlNo Type ProductID Group 1 1 1.0 A 2 1 2.0 B 3 2 3.0 B 4 1 4.0 A
Arindam Banerjee Sr. Software Developer Rance Computer Pvt Ltd. Kolkata (India)
You can use CASE to modify the result based on the value, like:
SELECT
...
CASE
WHEN (Type = 2) THEN (SELECT Group FROM TableName WHERE ???)
ELSE Group
END,
...
FROM TableNamebut the problem is, how you identify the previous product group? There should be somekind of logic for that.
The need to optimize rises from a bad design.My articles[^]