Wednesday, May 15, 2013

Convert a SQL query result table to an HTML table for email

declare @body varchar(max)

set @body = cast( (
select td = dbtable + '' + cast( entities as varchar(30) ) + '' + cast( rows as varchar(30) )
from (
select dbtable = object_name( object_id ),
entities = count( distinct name ),
rows = count( * )
from sys.columns
group by object_name( object_id )
) as d
for xml path( 'tr' ), type ) as varchar(max) )

set @body = '' + ' ' + replace( replace( @body, '<', '<' ), '>', '>' ) + '
Database TableEntity CountTotal Rows
'

print @body

 <html>
   <head >
   </head>
   <body>
   <body>
 <html>

http://stackoverflow.com/questions/7070053/convert-a-sql-query-result-table-to-an-html-table-for-email

SQL Cast and Convert Date

Using SQL Server 2008
This first option of removing the date uses the SQL Server 2008 method. This will return only the date or only the time:

-- remove the time
SELECT CAST(GETDATE() AS DATE) -- 2009-07-12
-- remove the date
SELECT CAST(GETDATE() AS TIME) -- 08:46:25.8130000
If you’re not working with SQL Server 2008, you have to improvise.

Cast Date With No Time Using Floor
This example removes the time from the date time by setting it to the beginning of the day.

-- Get the current day with no time
-- 2009-06-29 00:00:00.000
SELECT CAST(FLOOR(CAST(GETDATE() AS FLOAT)) AS datetime)

-- Get the next day
-- 2009-06-30 00:00:00.000
SELECT CAST(CEILING (CAST(GETDATE() AS FLOAT)) AS datetime)
Cast Date with No Time Using Convert
Using convert you can remove the time for display purposes, usually for reporting or the front end.

-- Month first
SELECT CONVERT(VARCHAR(12),GETDATE(), 101) -- 06/29/2009
SELECT CONVERT(VARCHAR(12),GETDATE(), 110) -- 06-29-2009
SELECT CONVERT(VARCHAR(12),GETDATE(), 100) -- Jun 29 2009
SELECT CONVERT(VARCHAR(12),GETDATE(), 107) -- Jun 29, 2009

-- Year first
SELECT CONVERT(VARCHAR(12),GETDATE(), 102) -- 2009.06.29
SELECT CONVERT(VARCHAR(12),GETDATE(), 111) -- 2009/06/29
SELECT CONVERT(VARCHAR(12),GETDATE(), 112) -- 20090629

-- Day first
SELECT CONVERT(VARCHAR(12),GETDATE(), 103) -- 29/06/2009
SELECT CONVERT(VARCHAR(12),GETDATE(), 105) -- 29-06-2009
SELECT CONVERT(VARCHAR(12),GETDATE(), 104) -- 29.06.2009
SELECT CONVERT(VARCHAR(12),GETDATE(), 106) -- 29 Jun 2009

-- Time only
SELECT CONVERT(VARCHAR(12),GETDATE(), 108) -- 07:26:16
SELECT CONVERT(VARCHAR(12),GETDATE(), 114) -- 07:27:11:203
Roll Your Own Date
To roll your own date format, use the datename function. This is also the only way to get the full month name.

SELECT DATENAME(MONTH, GETDATE()) -- June
SELECT DATENAME(DAY,GETDATE()) -- 29
SELECT DATENAME(YEAR, GETDATE()) -- 2009

-- Concatente values
-- June.29.2009
SELECT DATENAME(MONTH, GETDATE()) + '.' + DATENAME(DAY,GETDATE()) + '.' + DATENAME(YEAR, GETDATE())
Here are the rest of the possible datepart intervals:

Date Part Name Interval Values
Year year, yyyy, yy
Quarter quarter, q, qq
Month month, mm, mm
Day of the year dayofyear, dy, y
Day day, dd,. D
Weekday weekday, dw
Week week, wk, ww
Hour hour, hh
Minute minute, mi, n
Second second, ss, s

http://sqlserverplanet.com/tsql/cast-date

Thursday, August 16, 2012

Select เฉพาะวันที่ใน SQL Server

SELECT DATEADD(D, 0, DATEDIFF(D, 0, GETDATE()))

I approved his method though, I finally suggested my method using function CONVERT.
SELECT CONVERT(VARCHAR(10),GETDATE(),111)

http://blog.sqlauthority.com/2007/06/10/sql-server-retrieve-select-only-date-part-from-datetime-best-practice/

Monday, July 2, 2012

ปิดหน้าต่าง window browser โดยไม่มี message เตือ ie7 ขึ้นไป


<script language="javascript" type="text/javascript">
function CloseWindow()
{
var userBrowser = navigator.userAgent;
//alert (userBrowser)
if ((userBrowser.indexOf('MSIE')>0)) {
window.open('', '_self', '');
window.close();
}
else {
window.opener = '';
window.close(); // attempt to close window first, show user warning message if fails
alert("To avoid data corruption/loss. Please close this window immedietly.");
}
}
</script>

โปรแกรมช่วยเปลี่ยนอักษรภาษาอังกฤษ จากพิมพ์เล็กไปพิมพ์ใหญ่ จากพิมพ์ใหญ่ไปพิมพ์เล็ก

แค่โหลดลงเครื่องแล้วดับเบิ้ลคลิ๊กเปิดตัว exe ไว้
กด  Ctrl + Shift + U เพื่อเปลี่ยนเป็นตัว Uppercase
กด Ctrl + Shift + L เพื่อเปลี่ยนเป็นตัว Lowercase

รายละเอียดอ่านได้ที่เว็บนี้เลย
http://www.tothepc.com/archives/change-text-to-uppercase-lowercase-shortcut-hotkey/

ดาวน์โหลด
http://www.softpedia.com/get/Office-tools/Clipboard/Softspecialists-ClipCase.shtml

Thursday, June 28, 2012

Oracle Query Tools

รวมโปรแกรมสำหรับ Query Oracle Database

- Oracle SQL Developer (Free)
http://www.oracle.com/technetwork/developer-tools/sql-developer/downloads/index.html

- PL/SQL Developer (Free Trial)
http://www.allroundautomations.com/

- DreamCoder SQL Developer (Free)
http://www.sqldeveloper.net/

-Toad for Oracle
http://toadfororacle.com/index.jspa

- Navicat for Oracle
http://www.navicat.com/


ข้อมูลบางส่วนมาจาก
http://www.narisa.com/forums/index.php?showtopic=28424

โปรแกรม ColorPic สำหรับดึงค่าสีต่าง ๆ จาก Windows

โปรแกรม ColorPic สำหรับดึงค่าสีต่าง ๆ จาก Windows เป็น Freeware

เหมาสำหรับ Web Design ครับ

Download ได้ที่นี่เลย
http://www.iconico.com/download.aspx?app=ColorPic&type=free

วิธีใช้
http://www.iconico.com/colorpic/gettingStarted.aspx