create table #user(id int, superiorid int)
insert into #user(id, superiorid) values (1,null), (2,1) , (3,1) Search This Blog
Tuesday, March 26, 2013
Insert multiple rows WITHOUT repeating INSERT INTO SQL Server
SQL Server > Scripts > Insert multiple rows
Etichete:
SQL Server
Get all children of a parent SQL Server
SQL Server > With > Scripts
Get all children of a parent SQL Server
Example:
(
select u.superiorid, u.id
from #user u
where u.ID = @id
union all
select u.superiorid ,u.ID
from #user u
inner join Parent p on p.id = u.superiorid
)
inner join Parent p on p.id = #user.id
Get all children of a parent SQL Server
In a hierarchical structure of tables is necessary to traverse the entire structure to find all the children of a parent.
Example:
create table #user(id int, superiorid int)
insert into #user(id, superiorid) values (1,null), (2,1) , (3,1)
declare @id int
select @id = 1;
with Parent (superiorid,id)
as(
select u.superiorid, u.id
from #user u
where u.ID = @id
union all
select u.superiorid ,u.ID
from #user u
inner join Parent p on p.id = u.superiorid
)
Select #user.id, #user.superiorid
from #user inner join Parent p on p.id = #user.id
drop table #user
Result:
id superiorid
1 NULL
2 1
3 1
Result:
id superiorid
1 NULL
2 1
3 1
Etichete:
SQL Server
Object JavaScript
In JavaScript you can define and create your own objects.
<body>
<script>
var car = new Object();
car.type = "Audi";
car.speed = "300";
document.write(car.type + " speed is " + car.speed + " KM/Hour.");
</script>
</body>
</html>
<!DOCTYPE html>
<html><body>
<script>
var car = new Object();
car.type = "Audi";
car.speed = "300";
document.write(car.type + " speed is " + car.speed + " KM/Hour.");
</script>
</body>
</html>
Etichete:
Java Script
Display date Java Script
Java Script > Date
<head>
<script>
function displayDate() {
document.getElementById("date").innerHTML = Date();
}
</script>
</head>
<body>
<h1>Display date JavaScript</h1>
<p id="date">Click button to display date</p>
<button type="button" onclick="displayDate()">Display Date</button>
</body>
</html>
<!DOCTYPE html>
<html><head>
<script>
function displayDate() {
document.getElementById("date").innerHTML = Date();
}
</script>
</head>
<body>
<h1>Display date JavaScript</h1>
<p id="date">Click button to display date</p>
<button type="button" onclick="displayDate()">Display Date</button>
</body>
</html>
Etichete:
Java Script
XML query() Method SQL Server
Specifies an XQuery against an instance of the xml data type.
Example:
SELECT @Doc.query('/Root/Order/Items')
<Items>
<Item>Item 1</Item>
<Item>Item 2</Item>
</Items>
Example:
declare @Doc xml
set @Doc = '<Root>
<Order OrderID="1" CustomerName="John">
<Items>
<Item>Item 1</Item>
<Item>Item 2</Item>
</Items>
</Order>
</Root>'
Reult:
<Items>
<Item>Item 1</Item>
<Item>Item 2</Item>
</Items>
Etichete:
SQL Server
Cleans all pages in all files of the SQL Server database
SQL Server > System Stored Procedures > sp_clean_db_free_space
Before you run sp_clean_db_free_space, it is recommend to create a full database backup.
Example
Cleans all pages in all files of the database.
Under some circumstances, the deleted rows can physically remain on the data page as a ghost records.
You can use sp_clean_db_free_space to clean these ghost records.Before you run sp_clean_db_free_space, it is recommend to create a full database backup.
Example
USE Master
GO
EXEC sp_clean_db_free_space @dbname = N'YourDBName';
Etichete:
SQL Server
Monday, March 25, 2013
Handle NetworkAvailabilityChanged event in C# Windows Forms
C# > System.Net > NetworkInformation > NetworkChange > NetworkAvailabilityChanged
NetworkAvailabilityChanged occurs when the availability of the network changes.
Example
Check network available.
Edit Program.cs: Add event to check network is available
using System.Linq;
using System.Net.NetworkInformation;
using System.Windows.Forms;
static class Program
{
///
/// The main entry point for the application.
///
if (e.IsAvailable)
{
MessageBox.Show ("Network Available");
}
else
{
MessageBox.Show("Network Unavailable");
}
}
[STAThread]
static void Main()
{
NetworkChange.NetworkAvailabilityChanged += NetworkAvailabilityChanged;
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
NetworkAvailabilityChanged occurs when the availability of the network changes.
Example
Check network available.
Edit Program.cs: Add event to check network is available
using System;
using System.Collections.Generic;using System.Linq;
using System.Net.NetworkInformation;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{static class Program
{
///
/// The main entry point for the application.
///
private static void NetworkAvailabilityChanged(object sender, NetworkAvailabilityEventArgs e)
{if (e.IsAvailable)
{
MessageBox.Show ("Network Available");
}
else
{
MessageBox.Show("Network Unavailable");
}
}
[STAThread]
static void Main()
{
NetworkChange.NetworkAvailabilityChanged += NetworkAvailabilityChanged;
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
Etichete:
c#
Subscribe to:
Posts (Atom)