Saturday, September 11, 2021
Row wise data view as Colomn wise using PIVOT Column
Saturday, June 5, 2021
Create DEMO DATE
declare @StartDT SMALLDATETIME='2017-05-01',
@EndDT SMALLDATETIME='2017-05-30',
@BUNIT_ID INT=10084
-- '2021-05-01','2021-05-31', 10084
;WITH DateRange(DateData) AS
(
SELECT @StartDT as Date
UNION ALL
SELECT DATEADD(d,1,DateData)
FROM DateRange
WHERE DateData < @EndDT
)
SELECT [DateData],@BUNIT_ID [BunitID] INTO #DATEX
FROM DateRange
OPTION (MAXRECURSION 0);
Sunday, December 27, 2020
Why do we have to write SET FMTONLY OFF in stored procedures when using Entity Framework ?
IF 1=0
BEGIN
SET FMTONLY OFF
END
-----------------------------------------------------
Having IF(0=1) SET FMTONLY OFF seems like a risky thing to casually do in stored procedures read in by entity framework.
Entity Framework is the only source of this flag being set as a standard practice that I'm aware of (presumably other ORM's may use it).
the purpose (as I understand it) is to provide a way to get a procedures return schema without actually touching any data. (some stored procedures you don't want to execute just to update an orm's object model.
so unless you have a table that is counting the number of times your EF model has been updated (which might be interesting academically)
the safest way to use ftmonly with entity framework (in my mind) is.. under the following circumstances
- if the procedure in question is complex and confuses EF (EF reads the first returned schema, flow logic ignored)
- let EF set the flag for you. (I clear it below to exit early)
- use always false logic (which would be ignored when FTMONLY is on - interpret this as EF is trying to read schema)
at the beginning of the complex procedure do the following
if(0=1) -- if FMTONLY is on this if condition is ignored begin -- this loop will only be entered if fmtonly is on (ie EF schema read) select column1 ,column2 ... ,columnX from whateverA cross join whateverB ... cross join whateverQ -- joins don't matter but they might make it easier to get the column definitions -- and names you desire. the important thing here is generating the proper -- return schema... which is as complex as whatever you are trying to return where 1=0 set FMTONLY off -- do this so that you can now force an early return since EF -- usually only wants the first data set schema... other orms might -- do something different return -- this will be ignored if FMTONLY is still on end
Sunday, November 29, 2020
SQL Server CURSOR
What is a database cursor ?
These are steps for using a cursor:
Tuesday, August 6, 2019
How to remove same data in a table row by javascript.
<tr><th>Category</th><th>Product</th><th>Size</th><th>Price</th><th>Shipping</th></tr>
<tr><td>Category-1</td><td>Product-1</td><td>Big</td><td>102</td><td>Free</td></tr>
<tr><td>Category-1</td><td>Product-1</td><td>Big</td><td>132</td><td>Free</td></tr>
<tr><td>Category-1</td><td>Product-2</td><td>Big</td><td>130</td><td>Free</td></tr>
<tr><td>Category-1</td><td>Product-2</td><td>Small</td><td>100</td><td>Free</td></tr>
<tr><td>Category-2</td><td>Product-3</td><td>Big</td><td>130</td><td>Free</td></tr>
<tr><td>Category-2</td><td>Product-3</td><td>Big</td><td>100</td><td>Free</td></tr>
<tr><td>Category-2</td><td>Product-3</td><td>Small</td><td>100</td><td>10</td></tr>
<tr><td>Category-2</td><td>Product-4</td><td>Big</td><td>150</td><td>10</td></tr>
<tr><td>Category-3</td><td>Product-5</td><td>Big</td><td>150</td><td>10</td></tr>
<tr><td>Category-3</td><td>Product-5</td><td>Small</td><td>120</td><td>10</td></tr>
<tr><td>Category-3</td><td>Product-5</td><td>Big</td><td>120</td><td>Free</td></tr>
<tr><td>Category-4</td><td>Product-6</td><td>Big</td><td>120</td><td>10</td></tr>
<tr><td>Category-4</td><td>Product-6</td><td>Small</td><td>120</td><td>10</td></tr>
</table>
-----------------------------------------------------------------------------
$(function () {
function groupTable($rows, startIndex, total) {
if (total === 0) {
return;
}
var i, currentIndex = startIndex, count = 1, lst = [];
var tds = $rows.find('td:eq(' + currentIndex + ')');
var ctrl = $(tds[0]);
lst.push($rows[0]);
for (i = 1; i <= tds.length; i++) {
if (ctrl.text() == $(tds[i]).text()) {
count++;
$(tds[i]).addClass('deleted');
lst.push($rows[i]);
}
else {
if (count > 1) {
ctrl.attr('rowspan', count);
groupTable($(lst), startIndex + 1, total - 1)
}
count = 1;
lst = [];
ctrl = $(tds[i]);
lst.push($rows[i]);
}
}
}
groupTable($('#tbl tr:has(td)'), 0, 3);
$('#tbl .deleted').remove();
});
Saturday, May 11, 2019
For Start New Promotion Sale Please Execute it all server
--- Aikhane apni connect er ip likhben r ai block chalaben
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[USP_Channel_Customer_List]
AS
BEGIN
if @ChID!=0
BEGIN
IF @ChID=109
BEGIN
UPDATE SYSSETTING SET Channel_POS_BILL_OLD = Channel_POS_BILL, Channel_POS_BILL = 1
SELECT PInt_ID,
Partner_ID+'_'+PartnerName+' ('+[Address]+')' [PartnerName],
ChID,
CAST(ROUND(DiscAllowed, 0, 0) AS INT) AS DiscAllowed
FROM [POSX].[dbo].[PARTNER_MASTER]Where [ChID]=@ChID
END
ELSE
BEGIN
UPDATE SYSSETTING SET Channel_POS_BILL = Channel_POS_BILL_OLD
SELECT PInt_ID,
Partner_ID+'_'+PartnerName+' ('+[Address]+')' [PartnerName],
ChID,
CAST(ROUND(DiscAllowed, 0, 0) AS INT) AS DiscAllowed
FROM [dbo].[PARTNER_MASTER]Where [ChID]=@ChID
END
--109
--[SYSSETTING]
END
ELSE if @ChID=0
BEGIN
SELECT PInt_ID,
Partner_ID+'_'+PartnerName+' ('+[Address]+')' [PartnerName],
ChID,
CAST(ROUND(DiscAllowed, 0, 0) AS INT) AS DiscAllowed
FROM [dbo].[PARTNER_MASTER]Where [ChID] not in(0)
END
END
--uporer ta chalano hole chicher ta chalaben
--
--- Aikhane apni connect er ip likhben
Tuesday, April 9, 2019
ট্রানজেক্সন ফেইল হলে এইটা চালাতে হবে।
DECLARE @SLID INT,
@REFID INT,
@DEVID INT
SELECT @SLID = MAX(LASTSERIALNO) FROM SYSDOCSRNO D
INNER JOIN SYSCREGISTER R ON D.REGID=R.REGISTERID
INNER JOIN SYSBUSINESSDAY Y ON Y.BUNIT_ID=R.BUNIT_ID
WHERE DOCUMENTID='POS';
SELECT @REFID=MAX(REF_ID) FROM SALES_POSSALE_HEADER D
INNER JOIN SYSCREGISTER R ON D.Device_ID=R.REGISTERID
INNER JOIN SYSBUSINESSDAY Y ON Y.BUNIT_ID=R.BUNIT_ID;
SELECT @DEVID=MIN(REGID) FROM SYSDOCSRNO WHERE DOCUMENTID='POS' AND LASTSERIALNO=@SLID;
IF @SLID=@REFID
BEGIN
UPDATE SYSDOCSRNO SET LASTSERIALNO=LASTSERIALNO+1 WHERE REGID=@DEVID AND DOCUMENTID='POS'
END
--SELECT @SLID [SL] SELECT @REFID [REF] SELECT @DEVID [DEVICE]
