<?xml version="1.0" encoding="UTF-8" ?>
<rdf:RDF 
  xmlns="http://purl.org/rss/1.0/"
  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
  xmlns:dc="http://purl.org/dc/elements/1.1/"
  xml:lang="en">
  <channel rdf:about="http://sscheral.atwiki.com/">
    <title>Welcome to Shivshanker&#039;s Blog</title>
    <link>http://sscheral.atwiki.com/</link>
    <description>I struggled to solve some problems so i want to share my solutions and who use these code they once test it and use it. </description>

    <dc:language>en</dc:language>
    <dc:date>2008-08-01T13:48:31+09:00</dc:date>

    <items>
      <rdf:Seq>
                <rdf:li rdf:resource="http://sscheral.atwiki.com/page/SQL%20Date%20Time" />
                <rdf:li rdf:resource="http://sscheral.atwiki.com/page/Welcome%20to%20Shivshanker%20Page" />
                <rdf:li rdf:resource="http://sscheral.atwiki.com/page/Know%20your%20IDENTITY" />
                <rdf:li rdf:resource="http://sscheral.atwiki.com/page/How%20to%20retrieve%20the%20last%20day%20of%20the%20month%20....%20Or%20Last%20date%20in%20the%20week" />
                <rdf:li rdf:resource="http://sscheral.atwiki.com/page/ASP%20Databound" />
                <rdf:li rdf:resource="http://sscheral.atwiki.com/page/ASP.NET%20Differences" />
                <rdf:li rdf:resource="http://sscheral.atwiki.com/page/Links" />
                <rdf:li rdf:resource="http://sscheral.atwiki.com/page/SQL%20UNION%2C%20SQL%20INTERSECT%2C%20SQL%20EXCEPT%2C%20SQL%20EXISTS%20and%20SQL%20CASE%20for%20Beginners" />
                <rdf:li rdf:resource="http://sscheral.atwiki.com/page/SQL%20Parse%20Array%20Function" />
                <rdf:li rdf:resource="http://sscheral.atwiki.com/page/Operators%20T-SQL%3A" />
              </rdf:Seq>
    </items>
  </channel>
    <item rdf:about="http://sscheral.atwiki.com/page/SQL%20Date%20Time">
    <title>SQL Date Time</title>
    <link>http://sscheral.atwiki.com/page/SQL%20Date%20Time</link>
    <description>
      
DECLARE @Date datetime
SET @Date = '2001/08/31'
SELECT DATEADD(dd,-(DATEPART(dw, @Date) - 1),@Date) AS 'First day of the
week'
SELECT DATEADD(dd,-(DATEPART(dw, @Date) - 7),@Date) AS 'Last day of the
week'
SELECT DAY(DATEADD(d, -DAY(DATEADD(m,1,@Date)),DATEADD(m,1,@Date))) AS 'Last
day of the month'

==============================================================================================================
--To get the first day of month and day name by any date
Declare @pInputDate Datetime
set @pInputDate=getdate()- 40
set @pInputDate= CAST(CAST(YEAR(@pInputDate) AS VARCHAR(4)) + '/' +
               CAST(MONTH(@pInputDate) AS VARCHAR(2)) + '/01' AS DATETIME)
--Will give First date of the month
--Will give day of the date
select @pInputDate AS First_Day_of_mth, datename(dw,@pInputDate) AS
Day_Name
==============================================================================================================
Hi,
     here is the Table:
Id    Saledate            Sales
1    2 Jan 2006          100
1    13 Jan 2006        200
1    14 Feb 2006        300
2    3 Feb 2006          150
2    4 Feb 2006           200
3    5 Jan 2006           300
3    13 Feb 2006         400
         I need the following output?
Id       Jan     Feb     Mar    Apr
1        300     300      0        0
2         0         350      0        0
3        300     400      0       0

--Here is the result:
SELECT ID, SUM(CASE WHEN MONTH(saledate) = 1 THEN sales ELSE 0 END) AS
'Jan',
   SUM(CASE WHEN MONTH(saledate) = 2 THEN ISNULL(sales,0) ELSE 0 END) AS
'Feb',
   SUM(CASE WHEN MONTH(saledate) = 3 THEN ISNULL(sales,0) ELSE 0 END) AS
'Mar',
   SUM(CASE WHEN MONTH(saledate) = 4 THEN ISNULL(sales,0) ELSE 0 END) AS
'Apr'
FROM sale
GROUP BY ID
--Here it is shown only for 4 months. You can extend this query for complete
year.

-- It gives maximum sales in each month
select id as ID ,
MAX(case when month(saledate) =1 then isnull(sales,0) else 0 end) as 'Jan',
MAX(case when month(saledate) = 2 then isnull(sales,0) else 0 end) as
'Feb',
Max(case when month(saledate) = 3 then isnull(sales,0) else 0 end) as
'Mar',
Max(case when month(saledate) = 4 then isnull(sales,0) else 0 end) as
'Apr',
Max(case when month(saledate) = 5 then isnull(sales,0) else 0 end) as
'May',
Max(case when month(saledate) = 6 then isnull(sales,0) else 0 end) as
'June',
Max(case when month(saledate) = 7 then isnull(sales,0) else 0 end) as
'July',
Max(case when month(saledate) = 8 then isnull(sales,0) else 0 end) as
'Aug',
Max(case when month(saledate) = 9 then isnull(sales,0) else 0 end) as
'Sept',
Max(case when month(saledate) = 10 then isnull(sales,0) else 0 end) as
'Oct',
Max(case when month(saledate) = 11 then isnull(sales,0) else 0 end) as
'Nov',
Max(case when month(saledate) = 12 then isnull(sales,0) else 0 end) as
'Dec'
from sale
group by month(saledate),id
 

SELECT
    DAY('5/5/2007'),
    MONTH('5/1/2007'),
    YEAR('5/1/2007'),
    DATEPART(DAY, '1/5/2007'),
    DATEPART(MONTH, '5/1/2007'),  
    DATEPART(YEAR, '1/1/2007')
Day         MOnth       year        datepart_Day datepart_MOnth
datepart_year
======-- ======-- ======-- ======--- ======----- ======----
5           5           2007        5            5              2007

SELECT
    GETDATE() AS local_date,
    GETUTCDATE() AS UTC_date
local_date              UTC_date
============----- ============-----
2007-05-08 19:12:50.687 2007-05-08 13:42:50.687

SELECT DATEADD(MONTH, 6, GETDATE())AS '6_months_from_now'

6_months_from_now
============-----
2007-11-08 19:12:50.687
==============================================================================================================
declare @datevar datetime
select @datevar = getdate()
/*Example for getdate() : getting current datetime*/
select getdate() [Current Datetime]
/*Example for dateadd : getting date 7 days from current datetime*/
select dateadd(dd, 7, @datevar) [Date 7 days from now]
/*Example for datediff : getting no of days passed since 01-01-2004*/
select datediff(dd,'20040101',@datevar) [No of days since 01-01-2004]
/*Example for datename : getting month name*/
select datename(mm, @datevar) [Month Name]
/*Example for datepart : getting week from date*/
select datepart(wk, @datevar ) [Week No]
/*Example for day : getting day part of date*/
select day (@datevar) [Day]
/*Example for month : getting month part of date*/
select month(@datevar) [Month]
/*Example for year : getting year part of date*/
select year(@datevar) [Year]
/* Getting the Day Name like monday tuesday... */
SELECT DATENAME(dw, GETDATE())
-- or
/* 0-monday,1-tuesday,2-wednesday ....7-monday,8-tuesday... */
SELECT DATENAME(dw, 0)

==============================================================================================================

    </description>
    <dc:date>2008-08-01T13:48:31+09:00</dc:date>
  </item>
    <item rdf:about="http://sscheral.atwiki.com/page/Welcome%20to%20Shivshanker%20Page">
    <title>Welcome to Shivshanker Page</title>
    <link>http://sscheral.atwiki.com/page/Welcome%20to%20Shivshanker%20Page</link>
    <description>
      Wiki is a type of websites. You can edit wiki pages easily.




     You can edit the content with WYSIWYG(HTML)-mode or TEXT-mode or WIKI-mode
     You can change web site style , If SignIn on page top right bottun. 
     Page Lock is signin user only. Lock-@id is @id user only editable. Lock-admin is admin only editable.



    </description>
    <dc:date>2008-08-01T13:48:27+09:00</dc:date>
  </item>
    <item rdf:about="http://sscheral.atwiki.com/page/Know%20your%20IDENTITY">
    <title>Know your IDENTITY</title>
    <link>http://sscheral.atwiki.com/page/Know%20your%20IDENTITY</link>
    <description>
      




Know your
Identity




 




 
Often we create tables that have identity
columns. An identity column is a special column in SQL Server that can
automatically take on values when an insert operation is done on the table.
What if you want to find out whether a table contains an identity column?? SQL
Server stores this information in the syscolumns table, but you can access this
information in many ways. In this article, we will see the various ways to
access information about whether a table has an identity
column.
 
Before we start off with
the methods, let's first create a table that has an identity column, like
this:
 
CREATE
TABLE samp_test
(
       
colA    INT IDENTITY,
       
colB    VARCHAR(10)
)
 
 
Method A
 
In the first method, we will fetch this
information from the syscolumns table. This table contains a column
called status
that contains various values.
If the value in this column contains hexadecimal 80, then it means that the corresponding
column contains an identity column. Here is how we can check
this:
 
IF (EXISTS
(SELECT name FROM syscolumns WHERE
       
OBJECT_NAME(id) = 'samp_test' AND status = 0x80))
       
PRINT 'Table has an identity column'
ELSE
       
PRINT 'Table does not have an identity column'
 
 
Method B
 
In the second method, we will see whether
a table has an identity column using the COLUMNPROPERTY function. This function takes an
argument IsIdentity
that indicates whether the
column is an identity column. Here is how we can do the check using this
function:
 
IF (EXISTS
(SELECT myTemp.IsIdentity FROM
       
(SELECT IsIdentity=COLUMNPROPERTY(id, name, 'IsIdentity')
               FROM syscolumns WHERE OBJECT_NAME(id) = 'samp_test') AS
myTemp
       
WHERE myTemp.IsIdentity = 1))
       
PRINT 'Table has an identity column'
ELSE
       
PRINT 'Table does not have an identity column'
 
 
This method is slightly convoluted since
the COLUMNPROPERTY function takes the name of the column as the parameter.
Thus, if we want to make a generic sort of a call, we need to iterate through
each column of a table using the syscolumns table and then make a call to the
COLUMNPROPERTY function. Finally we then run an EXISTS check over this derived
table to check for identity.
 
Method C
 
In the final method, we will use
the OBJECTPROPERTY
function to check whether a
table has an identity column. Here is how we can do the check using this
function:
 
IF
(OBJECTPROPERTY(OBJECT_ID('samp_test'), 'TableHasIdentity') =
1)
       
PRINT 'Table has an identity column'
ELSE
       
PRINT 'Table does not have an identity column'
 
 
This is the easiest of the lot. The
OBJECTPROPERTY function takes as parameter the name of the object to check (a
table in this case) and then the name of the property. We use the
OBJECT_ID function to get the ID of the object. We
then use the TableHasIdentity property to check if the table has an
identity column. One difference between this method and the others is that this
method does not give the name of the column which is the identity column, which
is possible using the other two methods.





    </description>
    <dc:date>2008-08-01T13:47:08+09:00</dc:date>
  </item>
    <item rdf:about="http://sscheral.atwiki.com/page/How%20to%20retrieve%20the%20last%20day%20of%20the%20month%20....%20Or%20Last%20date%20in%20the%20week">
    <title>How to retrieve the last day of the month .... Or Last date in the week</title>
    <link>http://sscheral.atwiki.com/page/How%20to%20retrieve%20the%20last%20day%20of%20the%20month%20....%20Or%20Last%20date%20in%20the%20week</link>
    <description>
      
How to retrieve the last
day of the month .... Or Last date in the week?
Answer:
To add a addendum ... how can I find out the number of days in a given
month.
eg. If I were to give you '2003-03-01' I should get 31.
If you feel its a bit tricky in nature then ... See the solutions below ...
DECLARE @Date datetime
SET @Date = '2000/02/1'
SELECT DATEADD(dd,-(DATEPART(dw, @Date) - 1),@Date) AS 'First day of the
week'
SELECT DATEADD(dd,-(DATEPART(dw, @Date) - 7),@Date) AS 'Last day of the
week'
SELECT DAY(DATEADD(d, -DAY(DATEADD(m,1,@Date)),DATEADD(m,1,@Date))) AS 'Last
day of the month'
Since the Last Day would yield you the number of days in a month then it anwers
my addendum question also. Some more solutions for the number of days in a
month are below:
DECLARE @d DATETIME
SET @d = '2003-02-1'
select datepart(dd, dateadd(dd, -(datepart(dd, dateadd(mm, 1, @d))),dateadd(mm,
1, @d))) AS 'Last day of the month'
GO
DECLARE @d DATETIME
SET @d = '2000-02-1'
SELECT CASE WHEN MONTH(@d) = 1
　　　　　 THEN 31
　　　　　 WHEN MONTH(@d) = 2
　　　　　 THEN CASE WHEN (YEAR(@d) % 4 = 0 AND YEAR(@d) % 100 &amp;lt;&amp;gt; 0)
OR
　　　　　　　　　　　　　 YEAR(@d) % 400 = 0
　　　　　　　　　　 THEN 29
　　　　　　　　　　 ELSE 28
　　　　　 END
　　　　　 WHEN MONTH(@d) = 3
　　　　　 THEN 31
　　　　　 WHEN MONTH(@d) = 4
　　　　　 THEN 30
　　　　　 WHEN MONTH(@d) = 5
　　　　　 THEN 31
　　　　　 WHEN MONTH(@d) = 6
　　　　　 THEN 30
　　　　　 WHEN MONTH(@d) = 7
　　　　　 THEN 31
　　　　　 WHEN MONTH(@d) = 8
　　　　　 THEN 31
　　　　　 WHEN MONTH(@d) = 9
　　　　　 THEN 30
　　　　　 WHEN MONTH(@d) = 10
　　　　　 THEN 31
　　　　　 WHEN MONTH(@d) = 11
　　　　　 THEN 30
　　　　　 WHEN MONTH(@d) = 12
　　　　　 THEN 31
　　　 END AS 'Last day of the month'
Whew .... That's a mess to understand ... Believe me they work ... :-) ...
There are hundreds of way the SQL Selects can be done ... This is just few of
them ... And one more ...

SELECT DAY(DATEADD(DAY,-1,DATEADD(MONTH,1,DATEADD(DAY,1-DAY(@d),@d)))) AS 'Last
day of the month'

Note: Some of the tips and tricks are subjected to some specific SQL Server
settings hence use them with loads of care.

    </description>
    <dc:date>2008-06-29T20:42:02+09:00</dc:date>
  </item>
    <item rdf:about="http://sscheral.atwiki.com/page/ASP%20Databound">
    <title>ASP Databound</title>
    <link>http://sscheral.atwiki.com/page/ASP%20Databound</link>
    <description>
       Protected Sub dgSurveys_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles dgSurveys.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then
            Dim hyp As HyperLink = CType(e.Row.Cells(0).Controls(0), HyperLink)
            Dim url As String = hyp.NavigateUrl
            Dim split1 As String() = url.Split(&quot;?&quot;)
            Dim finalUrl As String = split1(0)
            If split1.Length &gt; 1 Then
                finalUrl &amp;= &quot;?&quot;
                Dim split2 As String() = split1(1).Split(&quot;&amp;&quot;)
                Dim query As String
                Dim isFirstElement As Boolean = True
                For Each query In split2
                    If isFirstElement = False Then
                        finalUrl &amp;= &quot;&amp;&quot;
                    End If
                    If query.Split(&quot;=&quot;).Length &gt; 1 Then
                        finalUrl &amp;= query.Split(&quot;=&quot;)(0) &amp; &quot;=&quot; &amp; Server.UrlEncode(query.Split(&quot;=&quot;)(1))
                    Else
                        finalUrl = finalUrl.Substring(0, finalUrl.Length - 1)
                        finalUrl &amp;= Server.UrlEncode(&quot;&amp;&quot; &amp; query)
                    End If
                    isFirstElement = False
                Next
            End If
            hyp.NavigateUrl = finalUrl

            If DirectCast(e.Row.FindControl(&quot;lblDueCross&quot;), Label).Text = &quot;1&quot; Then
                e.Row.Cells.Item(3).ForeColor = Drawing.Color.Red
            End If
            dgSurveys.DataKeys(e.Row.RowIndex).Item(2).ToString()

            'Dim strKeyword As String = dgSurveys.DataKeys(e.Row.RowIndex).Item(14).ToString
            'If strKeyword = &quot;Gas Warm Air Furnace by Efficiency, State, Configuration Report&quot; Then

            'End If


            Dim tempStr As String = DirectCast(e.Row.FindControl(&quot;lblFreqType&quot;), Label).Text
            ' Code to Disable if the selected company did not fill 
            ' the monthly survey corresponding to the Quarterly survey
            If ChangeDBNullToEmptyString(Right(tempStr, (tempStr.Length - 1)).ToString)  &quot;&quot; Then
                If Left(tempStr, 1) = &quot;2&quot; Then ' Check Whether Survey is Quarterly or not
                    Dim count As Int16
                    Dim t As String = dgSurveys.DataKeys(e.Row.RowIndex).Values(2).ToString
                    Dim strsql As New System.Text.StringBuilder
                    Try
                        strsql.Append(&quot;GetThreeMonthlySurveyID &quot;)
                        strsql.Append(PrepareString(t) &amp; COMMA)
                        strsql.Append(PrepareString(Right(tempStr, (tempStr.Length - 1)).ToString))
                        sqlcmd.CommandTimeout = 1000
                        count = getSingleValue(sqlcmd, strsql.ToString)
                    Catch ex As Exception
                    End Try

                    If count &gt; 0 Then
                        'e.Row.Cells.Item(0).Enabled = False
                        e.Row.Cells.Item(0).Attributes.Add(&quot;style&quot;, &quot;cursor:hand&quot;)
                        Dim txt As String = CType(e.Row.Cells.Item(0).Controls(0), HyperLink).Text
                        e.Row.Cells.Item(0).Controls.Remove(e.Row.Cells.Item(0).Controls(0))
                        e.Row.Cells.Item(0).Text = txt
                        'e.Row.Cells.Item(0).CssClass = &quot;GridGray&quot;
                        e.Row.Cells.Item(0).ForeColor = Drawing.Color.Gray
                        e.Row.Cells.Item(0).Attributes.Add(&quot;onclick&quot;, &quot;alert('Please fill out the corresponding monthly survey first.')&quot;)
                        e.Row.Cells.Item(4).Enabled = False
                        e.Row.Cells.Item(6).Enabled = False
                        e.Row.Cells.Item(5).Text = &quot;Please fill out the corresponding monthly survey first&quot;
                        e.Row.Cells.Item(5).ForeColor = Drawing.Color.Red
                    End If
                End If
            End If
            Dim tblCellControl As System.Web.UI.WebControls.ImageButton = e.Row.Cells.Item(e.Row.Cells.Count - 1).FindControl(&quot;img1&quot;)
            tblCellControl.Attributes.Add(&quot;onclick&quot;, &quot;return getConfirm('Please note that uploading the Excel data will overwrite any data entered in the online form.\nDo you want to proceed?');&quot;)

            'Dim tblCellControl1 As System.Web.UI.WebControls.ImageButton = e.Row.Cells.Item(e.Row.Cells.Count - 1).FindControl(&quot;imgDownload&quot;)
            'tblCellControl1.Attributes.Add(&quot;onclick&quot;, &quot;return excelDownload();&quot;)

        End If
    End Sub
    </description>
    <dc:date>2008-05-11T19:04:16+09:00</dc:date>
  </item>
    <item rdf:about="http://sscheral.atwiki.com/page/ASP.NET%20Differences">
    <title>ASP.NET Differences</title>
    <link>http://sscheral.atwiki.com/page/ASP.NET%20Differences</link>
    <description>
      
Difference between Convert.ToInt32 and int.Parse
Both(Convert.ToInt32 and
int.Parse) will return the same resule in
most of the cases. But null is handled differently.
Consider the following example&amp;string strCount=&quot;32&quot;;
int count1 = Convert.ToInt32(strCount);
int count2 = int.Parse(strCount);

If you print the result it will be same ie 32.

If suppose the string is the null (see the example below),
Convert.ToInt32 will return zero.
but the int.Parse will throw ArgumentNullException
error.string strCount=null;
int count1 = Convert.ToInt32(strCount);
int count2 = int.Parse(strCount); // Error
If you don't assign (initialize) null to the strCount the code will
not compile.
Because in C# variable must be initialized before use.
&quot;Int32&quot; and
&quot;int&quot;
Well, when i searched msn, i found most of the people said
both are same, the only difference is coloring in the IDE.(ha!!). But one guy
from microsoft pointed out one difference that u cannot use Int32 in enum.
which will result in compiler error(Type byte, sbyte, short, ushort, int, uint,
long, or ulong expected). Quite intersting but microsft didn't accept this as
bug, they said it is by design.. This is only with C# and in VB.NET works
fine.
Dataset Vs DataReader




To better improve the
performance of a solution, we have to
understand the DataSet and DataReader and they have to be used correctly in the
places they needed. Let see how they work...

DataReader
Datareader is like a forward only recordset. It fetches one
row at a time so very less Network Cost compare to DataSet(Fetches all the rows
at a time). DataReader is readonly so we cannot do any transaction on them.
DataReader will be the best choice where we need to show the data to the user
which requires no transaction ie reports. Due to DataReader is forward only we
cannot fetch the data randomly. .NET Dataproviders optimizes the datareaders to
handle the huge amount of data.

DataSet
DataSet is always a bulky object that requires lot of memory space compare to
DataReader. We can say the dataset as a small database coz it stores the schema
and data in the application memory area. DataSet fetches all data from the
datasource at a time to its memory area. So we can traverse through the object
to get required data like qureying database.

The dataset maintains the relationships among the datatables inside
it. We can manipulate the realational data as XML using dataset.We can do
transactions (insert/update/delete) on them and finally the modifications can
be updated to the actual database. This provides impressive flexibility to the
application but with the cost of memory space. DataSet maintains the original
data and the modified data seperately which requires more memory space. If the
amount of data in the dataset is huge
then it will reduce the applications performance dramatically.

The following points will improve the performane of a dataset...

1. Don't use the commandbuilder to generate the sql statements.
Though it reduces the development time the query generated

by the command builder will not be always as required. For example
To update the details of an author table the command

builder will generate a query like this ...

Query generated by CommandBuilder UPDATE authors
SET
au_id = ?, au_fname = ?, au_lname = ?, phone = ?,
zip = ?, state = ?, city = ?, address = ?
WHERE
(au_id = ?)
AND (address = ? OR ? IS NULL AND address IS NULL)
AND (au_fname = ?)
AND (au_lname = ?)
AND (city = ? OR ? IS NULL AND city IS NULL)
AND (phone = ?)
AND (state = ? OR ? IS NULL AND state IS NULL)
AND (zip = ? OR ? IS NULL AND zip IS NULL)
But we can write much more efficient query than the above like
this ..UPDATE authors
SET
au_id = ?, au_fname = ?, au_lname = ?, phone = ?,
zip = ?, state = ?, city = ?, address = ?
WHERE
(au_id = ?)
2. Always select the columns required in the quries. Don't use &quot;select * from &amp;lt;table_name&amp;gt;&quot;. Take an example of authors
table which has the author id , name, address, image. For showning the author
name,address if we use select * then the image column also fetched from the
database which requires more memory and NetWork Cost will be more due the
amount of data. This will reduce the applications performance.

3. Always try to use the parameter collection for the stored
procedures. We can execute the stored proceduers in two ways.
a. we can create a string as a query and can execute it.
Ex &quot;getAuthor(7689)&quot;.
b. we can create a command object. Assign the Stored Procedure
name to the commandtext property. Specify the commandtype as stored procedure.
Create a parameter for the value passed to the SP and
execute.
Ex:SqlCommand sqlcmd = new
SqlCommand();
sqlcmd.CommandText=&quot;getAuthors&quot;;
sqlcmd.CommandType= CommandType.StoredProcedure;
SqlParameter sqlparam = new SqlParameter
(&quot;@au_id&quot;,SqlDbType.Int);
sqlparam.Value = 7689;
sqlcmd.Parameters.Add(sqlparam);
sqlcmd.Connection= con;
sqlcmd.ExecuteReader();
There are lot of difference between the way the two quries executed.
The first query will be sent to the database server as a string though we think
we are passing the author id as int. The database server will parse the query
and will determine the datatype of the parameter. This extra processing will
increase the execution time.

But while executing the second query the native datatype of the
parameter is sent to the database server as network packets throuh
RPC.








Difference between Convert.ToInt32 and
int.Parse



Both(Convert.ToInt32 and
int.Parse) will return the same resule in
most of the cases. But null is handled differently.
Consider the following example&amp; string strCount=&quot;32&quot;;
int count1 = Convert.ToInt32(strCount);
int count2 = int.Parse(strCount);

If you print the result it will be same ie 32.

If suppose the string is the null (see the example below),
Convert.ToInt32 will return zero.
but the int.Parse will throw ArgumentNullException error.
string
strCount=null;
int count1 = Convert.ToInt32(strCount);
int count2 = int.Parse(strCount); // Error
If you don't assign (initialize) null to the strCount the code will
not compile.
Because in C# variable must be initialized before use.






    </description>
    <dc:date>2008-04-19T00:00:35+09:00</dc:date>
  </item>
    <item rdf:about="http://sscheral.atwiki.com/page/Links">
    <title>Links</title>
    <link>http://sscheral.atwiki.com/page/Links</link>
    <description>
      http://jslint.com/
http://www.glasshaus.com/samplechapters/1051/default.asp
http://www.w3schools.com
    </description>
    <dc:date>2008-01-15T09:43:09+09:00</dc:date>
  </item>
    <item rdf:about="http://sscheral.atwiki.com/page/SQL%20UNION%2C%20SQL%20INTERSECT%2C%20SQL%20EXCEPT%2C%20SQL%20EXISTS%20and%20SQL%20CASE%20for%20Beginners">
    <title>SQL UNION, SQL INTERSECT, SQL EXCEPT, SQL EXISTS and SQL CASE for Beginners</title>
    <link>http://sscheral.atwiki.com/page/SQL%20UNION%2C%20SQL%20INTERSECT%2C%20SQL%20EXCEPT%2C%20SQL%20EXISTS%20and%20SQL%20CASE%20for%20Beginners</link>
    <description>
      


SQL UNION, SQL INTERSECT, SQL EXCEPT, SQL EXISTS and SQL
CASE for Beginners

 
SQL
UNION, SQL
INTERSECT,
SQL EXCEPT, SQL
EXISTS and SQL CASE
Table1  




 


C1


C2




1


A


B




2


A


C




3


A


D




Table2




 


C1


C2




1


A


B




2


A


C




3


A


E




SQL
UNION
The purpose of the SQL
UNION command is to combine the results of
two queries together. In this respect,
UNION is somewhat similar to JOIN in that they are
both used to related information from multiple tables. One restriction
of UNION is that all corresponding columns need to be
of the same data type. Also, when using
UNION, only distinct values are selected (similar
to SELECT DISTINCT).
The purpose of the SQL
UNION ALL command is also to combine the
results of two queries together. The difference between UNION
ALL and UNION
is that, while
UNION only selects distinct values,
UNION ALL selects all
values.
The syntax is as
follows:
[SQL Statement
1]
UNION [ALL]
[SQL Statement
2]
 
The following are basic rules for combining
the result sets of two queries by using UNION:

·             The number and the order of the columns must be the same in all
queries.

·             The data types must be compatible.
 




SELECT C1,C2 FROM T1
UNION
SELECT C1,C2 FROM T2
 


SELECT C1,C2 FROM T1
UNION ALL
SELECT C1,C2 FROM T2




Result:
 




 


C1


C2




1


A


B




2


A


C




3


A


D




4


A


E






Result:




 


C1


C2




1


A


B




2


A


C




3


A


D




4


A


B




5


A


C




6


A


e








 
 
 
SQL
INTERSECT
Similar to the
UNION command,
INTERSECT also operates on two SQL
statements. The difference is that, while
UNION essentially acts as an
OR operator (value is selected if it appears
in either the first or the second statement), the
INTERSECT command acts as an
AND operator (value is selected only if it
appears in both statements). Returns distinct values by comparing the results
of two queries.

INTERSECT
returns any distinct values that are returned by both the query on the left and
right sides of the INTERSECT operand.

The basic rules
for combining the result sets of two queries that use INTERSECT are the
following:

·             The number and the order of
the columns must be the same in all queries.

·             The data types must be
compatible.
The syntax is as
follows:
[SQL Statement
1]
INTERSECT
[SQL Statement
2]

 
SELECT C1,C2 FROM T1
INTERSECT
SELECT C1,C2 FROM T2
Result:




 


C1


C2




1


A


B




2


A


C





Note:
INTERSECT
will work only in SQL 2005.


SQL
EXCEPT
The
EXCEPT (MINUS) operates on two
SQL statements. It takes
all the results from the first SQL statement, and then subtract out the ones
that are present in the second SQL statement to get the final answer. If the
second SQL statement includes results not present in the first SQL statement,
such results are ignored.

EXCEPT returns
any distinct values from the left query that are not also found on the right
query.

The basic rules
for combining the result sets of two queries that use EXCEPT are the
following:

·             The number and the order of
the columns must be the same in all queries.

·             The data types must be
compatible.
The syntax is as
follows:
[SQL Statement
1]
EXCEPT
[SQL Statement
2]
 
 
SELECT C1,C2 FROM T1
EXCEPT
SELECT C1,C2 FROM T2
 
Result:




 


C1


C2




 
 


    </description>
    <dc:date>2007-11-30T11:21:28+09:00</dc:date>
  </item>
    <item rdf:about="http://sscheral.atwiki.com/page/SQL%20Parse%20Array%20Function">
    <title>SQL Parse Array Function</title>
    <link>http://sscheral.atwiki.com/page/SQL%20Parse%20Array%20Function</link>
    <description>
      

Yet another version of the function to return a table from a delimitted string of values


if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[fn_ParseCSVString]') and xtype in (N'FN', N'IF', N'TF'))
drop function [dbo].[fn_ParseCSVString]
GO


create function fn_ParseCSVString
(
@CSVString       varchar(8000) ,
@Delimiter varchar(10)
)
returns @tbl table (s varchar(1000))
as
/*
select * from dbo.fn_ParseCSVString ('qwe,c,rew,c,wer', ',c,')
*/
begin
declare @i int ,
 @j int
    select  @i = 1
    while @i &amp;lt;= len(@CSVString)
    begin
             select  @j = charindex(@Delimiter, @CSVString, @i)
                if @j = 0
         begin
                     select  @j = len(@CSVString) + 1
          end
               insert  @tbl select substring(@CSVString, @i, @j - @i)
            select  @i = @j + len(@Delimiter)
 end
       return
end

    </description>
    <dc:date>2007-09-27T11:46:14+09:00</dc:date>
  </item>
    <item rdf:about="http://sscheral.atwiki.com/page/Operators%20T-SQL%3A">
    <title>Operators T-SQL:</title>
    <link>http://sscheral.atwiki.com/page/Operators%20T-SQL%3A</link>
    <description>
      
Operators (T-SQL)
An operator is a symbol specifying an action that is performed on one or
more expressions. Microsoft® SQL Server™ uses these operator categories:

Arithmetic operators
Assignment operator
Bitwise operators
Comparison operators
Logical operators
String concatenation operator
Unary operators

Arithmetic Operators
Arithmetic operators perform mathematical operations on two expressions of
any of the data types of the numeric data type category. For more information
about data type categories, see Transact-SQL Syntax Conventions.



Operator
Meaning


+
(Add)
Addition.


-
(Subtract)
Subtraction.


*
(Multiply)
Multiplication.


/
(Divide)
Division.


%
(Modulo)
Returns the integer remainder of a division. For example, 12 %
5 = 2 because the remainder of 12 divided by 5 is 2.



 
The + and - operators can also be used to perform arithmetic operations on
datetime and smalldatetime values.
For information about the precision and scale of the result of an arithmetic
operation, see Precision,
Scale, and Length.
Assignment Operator
Transact-SQL has one assignment operator, the equals sign (=). In this
example, the @MyCounter variable is created. Then, the
assignment operator sets @MyCounter to a value returned by an
expression.
DECLARE @MyCounter INT
SET @MyCounter = 1
  
The assignment operator (=) can also be used to establish the relationship
between a column heading and the expression defining the values for the column.
This example displays two column headings named
FirstColumnHeading and SecondColumnHeading.
The string xyz is displayed in the FirstColumnHeading column
heading for all rows. Then, each product ID from the Products
table is listed in the SecondColumnHeading column heading.
USE Northwind
GO
SELECT FirstColumnHeading = 'xyz',
       SecondColumnHeading = ProductID
FROM Products
GO
  
Bitwise Operators
Bitwise operators perform bit manipulations between two expressions of any
of the data types of the integer data type category.



Operator
Meaning


&amp;amp;
(Bitwise AND)
Bitwise AND (two operands).


|
(Bitwise OR)
Bitwise OR (two operands).


^
(Bitwise Exclusive OR)
Bitwise exclusive OR (two operands).



 
The operands for bitwise operators can be any of the data types of the
integer or binary string data type categories (except for the
image data type), with the exception that both operands cannot
be any of the data types of the binary string data type category. The table
shows the supported operand data types.



Left operand
Right operand


binary
int, smallint, or
tinyint


bit
int, smallint,
tinyint, or bit


int
int, smallint,
tinyint, binary, or
varbinary


smallint
int, smallint,
tinyint, binary, or
varbinary


tinyint
int, smallint,
tinyint, binary, or
varbinary


varbinary
int, smallint, or
tinyint



 
Comparison Operators
Comparison operators test whether or not two expressions are the same.
Comparison operators can be used on all expressions except expressions of the
text, ntext, or image data
types.



Operator
Meaning


=
(Equals)
Equal to.


&amp;gt;
(Greater Than)
Greater than.


&amp;lt;
(Less Than)
Less than.


&amp;gt;=
(Greater Than or Equal To)
Greater than or equal to.


&amp;lt;=
(Less Than or Equal To)
Less than or equal to.


&amp;lt;&amp;gt; (Not Equal To)
Not equal to.


!=
(Not Equal To)
Not equal to (not SQL-92 standard).


!&amp;lt;
(Not Less Than)
Not less than (not SQL-92 standard).


!&amp;gt;
(Not Greater Than)
Not greater than (not SQL-92 standard).



 
The result of a comparison operator has the Boolean data type, which has
three values: TRUE, FALSE, and UNKNOWN. Expressions that return a Boolean data
type are known as Boolean expressions.
Unlike other SQL Server data types, a Boolean data type cannot be specified
as the data type of a table column or variable, and cannot be returned in a
result set.
When SET ANSI_NULLS is ON, an operator that has one or two NULL expressions
returns UNKNOWN. When SET ANSI_NULLS is OFF, the same rules apply, except an
equals operator returns TRUE if both expressions are NULL. For example, NULL =
NULL returns TRUE if SET ANSI_NULLS is OFF.
Expressions with Boolean data types are used in the WHERE clause to filter
the rows that qualify for the search conditions and in control-of-flow language
statements such as IF and WHILE, for example:
USE Northwind
GO
DECLARE @MyProduct int
SET @MyProduct = 10
IF (@MyProduct &amp;lt;&amp;gt; 0)
    SELECT *
    FROM Products
    WHERE ProductID = @MyProduct
GO
  
Logical Operators
Logical operators test for the truth of some condition. Logical operators,
like comparison operators, return a Boolean data type with a value of TRUE or
FALSE.



Operator
Meaning


ALL
TRUE if all of a set of comparisons are TRUE.


AND
TRUE if both Boolean expressions are TRUE.


ANY
TRUE if any one of a set of comparisons are TRUE.


BETWEEN
TRUE if the operand is within a range.


EXISTS
TRUE if a subquery contains any rows.


IN
TRUE if the operand is equal to one of a list of
expressions.


LIKE
TRUE if the operand matches a pattern.


NOT
Reverses the value of any other Boolean operator.


OR
TRUE if either Boolean expression is TRUE.


SOME
TRUE if some of a set of comparisons are TRUE.



 
For more information about logical operators, see the specific logical
operator topic.
String Concatenation Operator
The string concatenation operator allows string concatenation with the
addition sign (+), which is also known as the string concatenation operator.
All other string manipulation is handled through string functions such as
SUBSTRING.
By default, an empty string is interpreted as an empty string in INSERT or
assignment statements on data of the varchar data type. In
concatenating data of either the varchar,
char, or text data types, the empty string is
interpreted as an empty string. For example, ‘abc’ + ‘‘ +
‘def’ is stored as ‘abcdef’. However, if the sp_dbcmptlevel
compatibility level setting is 65, empty constants are treated as a single
blank character and ‘abc’ + ‘‘ + ‘def’ is stored as ‘abc
def’. For more information about the interpretation of empty strings, see
sp_dbcmptlevel.
Unary Operators
Unary operators perform an operation on only one expression of any of the
data types of the numeric data type category.



Operator
Meaning


+
(Positive)
Numeric value is positive.


-
(Negative)
Numeric value is negative.


~
(Bitwise NOT)
Returns the ones complement of the number.



 
The + (Positive) and - (Negative) operators can be used on any expression of
any of the data types of the numeric data type category. The ~ (Bitwise NOT)
operator can be used only on expressions of any of the data types of the
integer data type category.
Operator Precedence
When a complex expression has multiple operators, operator precedence
determines the sequence in which the operations are performed. The order of
execution can significantly affect the resulting value.
Operators have these precedence levels. An operator on higher levels is
evaluated before an operator on a lower level:

+ (Positive), - (Negative), ~ (Bitwise NOT)
* (Multiply), / (Division), % (Modulo)
+ (Add), (+ Concatenate), - (Subtract)
=, &amp;gt;, &amp;lt;, &amp;gt;=, &amp;lt;=, &amp;lt;&amp;gt;, !=, !&amp;gt;, !&amp;lt; (Comparison
operators)
^ (Bitwise Exlusive OR), &amp;amp; (Bitwise AND), | (Bitwise OR)
NOT
AND
ALL, ANY, BETWEEN, IN, LIKE, OR, SOME
= (Assignment)

When two operators in an expression have the same operator precedence level,
they are evaluated left to right based on their position in the expression. For
example, in the expression used in the SET statement of this example, the
subtraction operator is evaluated before the addition operator.
DECLARE @MyNumber int
SET @MyNumber = 4 - 2 + 27
-- Evaluates to 2 + 27 which yields an expression result of
29.
SELECT @MyNumber
  
Use parentheses to override the defined precedence of the operators in an
expression. Everything within the parentheses is evaluated first to yield a
single value before that value can be used by any operator outside of the
parentheses.
For example, in the expression used in the SET statement of this example,
the multiplication operator has a higher precedence than the addition operator,
so it gets evaluated first; the expression result is 13.
DECLARE @MyNumber int
SET @MyNumber = 2 * 4 + 5
-- Evaluates to 8 + 5 which yields an expression result of
13.
SELECT @MyNumber
  
In the expression used in the SET statement of this example, the parentheses
causes the addition to be performed first; the expression result is 18.
DECLARE @MyNumber int
SET @MyNumber = 2 * (4 + 5)
-- Evaluates to 2 * 9 which yields an expression result of
18.
SELECT @MyNumber
  
If an expression has nested parentheses, the most deeply nested expression
is evaluated first. This example contains nested parentheses, with the
expression 5 - 3 in the most deeply nested set of parentheses. This expression
yields a value of 2. Then, the addition operator (+) adds this result to 4,
which yields a value of 6. Finally, the 6 is multiplied by 2 to yield an
expression result of 12.
DECLARE @MyNumber int
SET @MyNumber = 2 * (4 + (5 - 3) )
-- Evaluates to 2 * (4 + 2) which further evaluates to 2 *
6, and
-- yields an expression result of 12.
SELECT @MyNumber
  
See Also
Functions

    </description>
    <dc:date>2007-09-26T07:16:05+09:00</dc:date>
  </item>
  </rdf:RDF>