Create Sample Table with Command GO [count] (T-SQL)

By adding a number (n) after GO, the batch will exexute n times. 

Here is a T-SQL snippet to create a sample table with 50 records in it:

<pre>

CREATE TABLE myNumTable   (id int identity(1,1),c1 datetime default getdate(), c2 varchar(50) default ‘test’)

GO

INSERT INTO myNumTable DEFAULT  
VALUES GO 50  

 

SELECT * FROM myNumTable 
</pre>

 

The GO is the signal to start a batch of T-SQL statement but itself is not a T-SQL statement. It is recognized by the sqlcmd and osql utilities.


Replace the Null Value With Previous Which Is Not Null

declare @t table (names varchar(5))
INSERT INTO @t SELECT 'sam'
UNION ALL SELECT null
UNION ALL SELECT null
UNION ALL SELECT null
UNION ALL SELECT 'jac'
UNION ALL SELECT null
UNION ALL SELECT null  

SELECT names FROM @t

declare @str VARCHAR(5)
UPDATE @t
SET @str=COALESCE(names,@str)
,names=@str

SELECT names FROM @t

http://social.msdn.microsoft.com/Forums/en/transactsql/thread/9353f696-33fc-44c0-9dab-86b8b71ed40b

How to Determine What Fiscal Year of Today Datein ASP.NET?

Here is a code snippet I posted early:

protected void Page_Load(object sender, EventArgs e)

{

int fYear;

if (DateTime.Today.Month < 7)

fYear = DateTime.Today.Year;

else

fYear = DateTime.Today.Year + 1;

Response.Write( “Current fisical year:”+fYear.ToString().Remove(0,2));

}


Format string with GridView

One user at ASP.NEt forum asked a question for how to format a 15 digit number(string) with two hyphen (-) inside at position 10 and 15.

It can be don easily in SQL:

SELECT  LEFT(@From,9) +’-‘+SUBSTRING(@From,10,5)+’-‘+RIGHT(@From,1)

The same can be done at the front end with string manipulation.

For the data column in GridView, we need to convert the BoundField to TemplateField first and apply the string.Insert to Eval at the designated position twice.

Text='<%# Eval(“rawCol”).ToString().Insert(9,”-“).Insert(15,”-“) %>’

We can see this in action below:

<asp:TemplateField HeaderText=”rawCol” SortExpression=”rawCol”>

<EditItemTemplate>

<asp:TextBox ID=”TextBox1″ runat=”server” Text='<%# Bind(“rawCol”) %>’></asp:TextBox>

</EditItemTemplate>

<ItemTemplate>

<asp:Label ID=”Label1″ runat=”server” Text='<%# Eval(“rawCol”).ToString().Insert(9,”-“).Insert(15,”-“) %>’></asp:Label>

</ItemTemplate>

</asp:TemplateField>

<asp:BoundField DataField=”col” HeaderText=”col” ReadOnly=”True”

SortExpression=”col” />

 


DNN 6.0 CTP released

The release of DNN 6.0 CTP is spread at DotnetNuke Site. I have downloaded the copy and istalled a fresh copy easily.

After a few minutes click and I need to start over again to resinstall it again with the app_pool set to ASP.NET 4.

I tested a function to create child portal with content from the Default My Website. It seems there is a bug in the process of creating the template. It include a invalid timezon element in the setting part. I submit it to the DNN forum.

I’ll keep posting my findings for this CTP.


SQL Server Change Authentication Mode (From Windows to Mixed) after Installation

When yo install SQL Server, you have a choice the server authentication mode from either Windows Authentication mode ot SQL Server and Windowns Authentication mode (mixed). If  you choose the Windows Authentication mode during install and you want to change it to mixed mode, you can find a step by step guild from MSDN site:

http://msdn.microsoft.com/en-us/library/ms188670.aspx

The T-SQL used by MSDN article:

<code>

ALTER LOGIN sa ENABLE ;
GO
ALTER LOGIN sa WITH PASSWORD = ‘<enterStrongPasswordHere>’ ;
GO

</code>


Redirect domain site root to another page with URLRewrite (IIS7)

There are two ways I know to do this:

1.Method1:

<rule name=”Redirect1_For_http://mysite.com/” stopProcessing=”true”>

<match url=”^\d*$” negate=”false” />

<action type=”Redirect” url=”redirect.aspx” />

</rule>

 

2. Method 2:

<rule name=”RedirectRootToAnotherPage” enabled=”true” stopProcessing=”true”>

<match url=”^$” />

<action type=”Redirect” url=”http://mysite.com/redirect.aspx&#8221; logRewrittenUrl=”true” />

</rule>

Read the rest of this entry »