DECLARE @tempTable TABLE (
userId INT,
userName NVARCHAR(50),
password NVARCHAR(50)
)
DECLARE @xml XML
SET @xml='
<row userId="67" userName="Kenny1" password="1234" />
<row userId="80" userName="Kenny2" password="5678" />'
INSERT INTO @tempTable
SELECT Tbl.Col.value('@userId', 'INT'),
Tbl.Col.value('@userName', 'NVARCHAR(50)'),
Tbl.Col.value('@password', 'NVARCHAR(50)')
FROM @xml.nodes('//row') Tbl(Col)
--See the table
SELECT * FROM @tempTable
2007/12/10
Convert xml to table in SQL 2005
This is how I convert XML string into a Table in SQL 2005:
2007/12/09
Web page search and SQL
Here is a way to search many columns in a table:
For example, if @userId = 1001, the
CREATE PROCEDURE [dbo].[SearchExample] (
@userId UNIQUEIDENTIFIER = NULL, --set all parameters' default value to null
@firstName NVARCHAR(50) = NULL,
@lastName NVARCHAR(50) = NULL,
@address NVARCHAR(100) = NULL,
@zipcode INT = NULL
)
SELECT ... --omit
FROM dbo.UserInfo u
WHERE u.userId = COALESCE(@userId, u.userId)
AND u.firstName LIKE ('%'+ COALESCE(@firstName, u.firstName)+'%')
AND ... --omit
... --omitSet the default value to null for all the input parameters is because if we don't have any filter to search (the value is null), then COALESCE() will use the second parameter as the output, otherwise it will output the first parameter.For example, if @userId = 1001, the
WHERE u.userId = COALESCE(@userId, u.userId)will become like
WHERE u.userId = 1001Otherwise, it will become like
WHERE u.userId = u.userId
2007/11/21
Brainstorming: Prefix and Postfix Operators
Another interested code segment talks about prefix and postfix operators:
Since x++ has a postfix operator, that means x will give its value to Console.WriteLine first, then perform the ++ operation. In contrast, prefix operator will perform ++ operation first, then give the value to Console.WriteLine.
class IncrementExampleThe result is
{
public static void Main()
{
int x = 1;
Console.WriteLine("{0}, {1}", x++, x++);
Console.WriteLine("{0}, {1}", ++x, ++x);
}
}
1, 2
4, 5
Since x++ has a postfix operator, that means x will give its value to Console.WriteLine first, then perform the ++ operation. In contrast, prefix operator will perform ++ operation first, then give the value to Console.WriteLine.
Brainstorming: An interested interview question
I saw this code segment on a blog:
The answer is:
The key point is the inner/nested class. We have to declare it is a public class so it's visible to everyone.
public class AWhat do you think the result will be? Don't forget this is a Interview question, that means you have to answer no more than few minutes.
{
void PrintA()
{
Console.WriteLine("Print A");
}
class B : Program
{
new void PrintA()
{
Console.WriteLine("Print B");
}
}
public static void Main()
{
A Atemp = new A();
B Btemp = new B();
Atemp.PrintA();
Btemp.PrintA();
}
}
The answer is:
Print AWhy not and how to get the following result?
Print A
Print A
Print B
The key point is the inner/nested class. We have to declare it is a public class so it's visible to everyone.
2007/11/20
Photo and Archive Merger (link updated)
Name: Kenny's Photo and Archive Merger
Version: 1.0
OS: Windows 2000/XP with .Net Framework 2.0 installed
Introduce:
In some circumstances you will need to hide your archive. For example, some free space only allow you to upload and store photos/images, and this program can help you to hide your archive in a photo/image. I believe you can have more ways to use this tool depend on your imaginations... :)
How to use:
1.Select a photo/image (to be a cloak)
2.Select an archive (to be cloaked)
3.Select a destination (don't forget to append the extension name, e.g. ".jpg")
4.Click Merge icon
That's it!
How to split:
Either 1.change the extension name from image type (.jpg) to original archive type (.rar or .zip) or 2.use the corresponding archiver (WinRAR or WinZIP) to open the photo/image directly.
Subscribe to:
Posts (Atom)