Jump to Navigation

Convert excel to mssql

First save excel to csv, then code below will do magic

CSRF verification tweaks for django 1.4

It has been headache to put CSRF verification while posting the form , the best way is to keep {% csrf_token %} just after form tag as below

{% extends "base.html" %}

{% block title %}My amazing blog{% endblock %}

{% block content %}

{% csrf_token %}
{{formdata.as_p}}

{% endblock %}

Make sure django.middleware.csrf.CsrfViewMiddleware is added to your middleware classes. Do not add django.middleware.csrf.CsrfResponseMiddleware
After that following code will work

Schedule daily backup for sql server 2005 datbase using sql agent

Scheduling a daily backup of sql server 2005 database using sql agent is very easy. By following below steps anyone can do that.

Open sql server 2005 Management Studio and connect a server
Expand the tree (left navigation) ”Management->Maintenance Plans”
Right click on node Maintenance Plans and Click “Maintenance Plan Wizard” (As shown in figure below) which causes to open a wizard.
1.jpg

4. Follow the wizard

Remove Alphabets in mssql

Need to list ABC2001 as 2001 some times ABCD2001 as 2001 .

alter function NoLetters(@string2number varchar(200)) returns varchar(200)
as
begin
declare @c int
declare @num varchar(200)
set @num = ''
declare @txtCurrent char(1)
set @c=1
while @c<=len(@string2number)
begin
set @txtCurrent = substring(@string2number,@c,1)
if ascii(@txtCurrent) between 48 and 57
set @num = @num + @txtCurrent
set @c=@c+1
end
return @num
end

Project Management in Nepal

The pictorial view of project management in nepal

Truncating leading zeros in mssql in variable data type

Need to match and group the same IDs generated from different machine, the query below rocks. Here i have removed leading zero using patindex

select count(test) as cnt,
substring(test, patindex('%[^0]%',test),len(test)) from (

select ('200003') as test
union
select '000200003' as test
union
select ('2A0003') as test
union
select ('002A0003') as test
)ty
group by substring(test, patindex('%[^0]%',test),len(test))

how to insert identity column manually in mssql

The table was as follows

Union VS Union All

I was working in ATM reconciliation of bank db from 3 different source. Here i found union was expensive than union all, since union all don't give unique results

UNION
The UNION command is used to select related information from two tables, much like the JOIN command. However, when using the UNION command all selected columns need to be of the same data type. With UNION, only distinct values are selected.

UNION ALL
The UNION ALL command is equal to the UNION command, except that UNION ALL selects all values.

MySql Group Concat

GROUP_CONCAT(expr) – This function returns a string result with the concatenated non-NULL values from a group.

Where it can be useful?

Subscribe to ersumit.com RSS


Main menu 2

by Dr. Radut.