Monday, November 21, 2011

Thursday, November 10, 2011

How to Build a Chrome Extension

I saw this article on lifehacker, thought it pretty cool: How to Build a Chrome Extension

Thursday, July 14, 2011

SQL capitalize words

this is from L.E.


set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

ALTER FUNCTION [dbo].[fn_capitalize]
(
@str AS nvarchar(100)
)
RETURNS nvarchar(100)
AS
BEGIN

DECLARE
@ret_str AS varchar(100),
@pos AS int,
@len AS int

SELECT
@ret_str = N' ' + LOWER(@str),
@pos = 1,
@len = LEN(@str) + 1

WHILE @pos > 0 AND @pos < @len
BEGIN
SET @ret_str = STUFF(@ret_str,
@pos + 1,
1,
UPPER(SUBSTRING(@ret_str,@pos + 1, 1)))
SET @pos = CHARINDEX(N' ', @ret_str, @pos + 1)
END
RETURN RIGHT(@ret_str, @len - 1)

END

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();
}