How to convert vertical data to horizontal in sql

Conversion of vertical data to horizontal in sql: Today I am going to show you how to convert vertical data to horizontal in ms sql. Here we have multiple ways by which we can convert vertical data to horizontal in sql. Here are some simple transformation of data from vertical to horizontal. 

Table structure


 display data vertically in sql
Insert Some data in table and select it

How to convert vertical data to horizontal in sql

Method1: to convert vertical data to horizontal in sql
Select * from PartsItem

Declare @ProductSKU varchar(MAX)='  '
select @ProductSKU= @ProductSKU+ ISNULL
(ProductSKU+', ' ' ') from PartsItem Select @ProductSKU as ProductSKUCode



 display data vertically in sql


Method2: to transformation of vertical data to horizontal in sql
It will show the record is in form of XML


Select ProductSKU + ' , '  from PartsItem for xml path ('  ')

How to convert vertical data to horizontal in sql





Read More

[Solved] How to add watermark in textbox in asp.net using ajax

Introduction : Today I am going to show you how to add water in textbox in asp.net webform using ajax.This is very simple to implement watermark in asp.net textbox. Let's see how we can done this.


                      
Ajextoolkit,TextBoxWatermarkExtender,Asp.net,C#,Watermark


Steps:
1.Add one asp.net webform.
2.Register the AjexToolKit assembley at the top of webform
3.Add the script in <head> section.
4.Add ToolKitScriptManager.
5.Take one textbox. 

Let's have a look

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="watermark-textbox.aspx.cs" Inherits="watermark-textbox" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajax" %>
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>how to add watermark in textbox in asp.net using ajax</title>
    <script type="text/javascript">
        function WaterMark(txtName, event) {
            var defaultText = "Enter Username Here";
            // Condition to check textbox length and event type
            if (txtName.value.length == 0 & event.type == "blur") {
                //if condition true then setting text color and default text in textbox
                txtName.style.color = "Gray";
                txtName.value = defaultText;
            }
            // Condition to check textbox value and event type
            if (txtName.value == defaultText & event.type == "focus") {
                txtName.style.color = "black";
                txtName.value = "";
            }
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <ajax:ToolkitScriptManager ID="k1" runat="server"></ajax:ToolkitScriptManager>
    <div>
        <b>UserName:</b>
        <asp:TextBox ID="txtUserName" runat="server" Text="Enter Username Here" ForeColor="Gray" onblur="WaterMark(this, event);" onfocus="WaterMark(this, event);" />
    </div>      
    </form>
</body>
</html>



TAG:Ajextoolkit,TextBoxWatermarkExtender,Asp.net,C#,Watermark

Read More

Function in SQL and use of SQL function at project level

Function in MS SQL Server,Use of function

Introduction:Function is used to perform the set of task or we can write multiple queries in a function and we can call n-number of times , So function gives me reusability of queries.

Why we create(make) function in MS SQL Server

Reusability:-Once we make a function we can call many times from asp.net application or any other application.

Actual Use of function at project level:

1.Function can return single value, it can’t return multiple value due to “returns” keyword.
2.Function can call another function.
3.At the project level the actual use of function is to perform the computational or calculation like to findout the no. of leave taken by the employee, sum of employee salary etc.
4.By the function we can fetch a record or search a record.
5.By the function we can’t perform DML operation(like insert,delete,update). This is the reason I wann go for Store procedure.


Note:

When we make a function it will go within DBO (DataBase Owner), became if we want to call the function we must include dbo.function name let’s see.

Create function [SearchName](@code int)
returns varchar(20)
as
   begin
       return 'Deepak'
   end

select dbo.SearchName(107) 

So, how many ways we can call function in Sql: There are following ways we can call function in MS SQL Server.

1.select dbo.SearchName(107)
2.print dbo.SearchName(107)
3.Declare @detail varchar(50)
SET @detail=dbo.SearchName(107)
print @detail




Function in SQL and use of SQL function at project level

Type of function in MS SQL Server:

If you go under programmability section,then you can see function is 3-Type

1.System Function
2.Table-Valued Function
3.Scaler-Valued Function


Function in SQL and use of SQL function at project level



Read More