Thursday, June 2, 2011

SQL - turn debug on-off

This is what I do in stored procedures to turn debug print stuff on and off


DECLARE @isDebug BIT; SET @isDebug = 0; IF @isDebug = 0 BEGIN SET NOCOUNT ON END
/* ... sql stuff ... */
IF @isDebug = 1 PRINT (@strSQL)

Tuesday, April 26, 2011

DataTable move the Column

If I don't put the code here, I bet I'll never find it again when I need it ...





DataColumn dc = dtRatesManagerAll.Columns["RateId"];
dc.SetOrdinal(dtRatesManagerAll.Columns.Count - 1);



Wednesday, April 13, 2011

Add inserted IDs in a temp table






CREATE TABLE #cucu(bau int)
CREATE TABLE #cucuafter(bau int)

INSERT INTO #cucu(bau)
OUTPUT inserted.[bau] INTO #cucuafter
SELECT RateTypeId
FROM TARFSS_RateType

select * from #cucu
select * from #cucuafter

drop TABLE #cucu
drop table #cucuafter




Thursday, March 10, 2011

Download file from server

Download xlsx file from server
(already created)






public void GenerateXLSXFile(string fileName, ExcelDocument theDocument)
{
string filePath = Server.MapPath("~/TempFiles/" + fileName + ".xlsx");
theDocument.esd_WriteXLSXFile(filePath);

Response.Clear();
Response.AddHeader("Content-Type", "application/vnd.ms-excel");
Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName + ".xlsx");
Response.WriteFile(filePath);

Response.Flush();
System.IO.File.Delete(filePath);
Response.End();
}



Thursday, September 30, 2010

SQL "not" for a variable

in c# i have a:

a = !a
(if false makes it true, if true makes it false)

in sql i want to do the same with a BIT variable, something like:


declare @a bit
set @a = 1
select @a
set @a = not (@a)
select @a


can i?

i could always do an IF, but this would "look better" :)

with the help of stackoverflow.com:
you can do either:
1. @a = @a ^ 1
or
2. @a = ~@a

i personally prefer #2

Monday, September 20, 2010

Friday, September 3, 2010