Wednesday, April 22, 2009

SQL right, left Modulo

declare @a int, @b int, @c int, @d int
select @a = 568788
select @b = left(@a,3)
select @c = right(left(@a,3),2)
select @d = right(left(@a,3),2)%10
SELECT @b, @c, @d

--Output
568 68 8

Sunday, March 22, 2009

SQL GROUP BY techniques

SELECT
C.CustomerID, C.CustomerName,
C.CustomerType, C.Address1, C.City,
C.State, S.TotalSales
FROM
Customers C
INNER JOIN
(SELECT
CustomerID, SUM(Sales) as TotalSales
FROM
Sales
GROUP BY
CustomerID) S
ON
C.CustomerID = S.CustomerID

Sunday, March 1, 2009

MS SQL Check for empty String

MS SQL one cannot use the <> '' on text, ntext and varchar data types:

SQL:

SELECT * FROM myTable WHERE myField LIKE '_%'

OR If you want to get all the field with empty string use

SQL:

SELECT * FROM myTable WHERE myField NOT LIKE '_%'

Thursday, February 5, 2009

What’s the maximum length for VARCHAR(MAX), NVARCHAR(MAX) and VARBINARY(MAX) data types?

The maximum storage size for VARCHAR(MAX) is 2^31-1 bytes (2,147,483,647 bytes or 2GB - 1 bytes). The storage size is the actual length of data entered + 2 bytes. The data entered can be 0 characters in length. Since each character in a VARCHAR data type uses one byte, the maximum length for a VARCHAR(MAX) data type is 2,147,483,645.

The maximum storage size for NVARCHAR(MAX) is also 2^31-1 bytes (2,147,483,647 bytes or 2GB - 1 bytes). The storage size, in bytes, is two times the number of characters entered + 2 bytes. The data entered can be 0 characters in length. Since each Unicode character in an NVARCHAR data type uses two bytes, the maximum length for an NVARCHAR(MAX) data type is 1,073,741,822.

The maximum storage size for VARBINARY(MAX) is the same as the maximum storage size for VARCHAR(MAX) and NVARCHAR(MAX), which is 2^31-1 (2,147,483,647 bytes or 2GB - 1 bytes). The storage size is the actual length of the data entered + 2 bytes. The data that is entered can be 0 bytes in length.

Wednesday, October 15, 2008

Google

WebSupergoo.ABCpdf6.Doc theDoc = new WebSupergoo.ABCpdf6.Doc();

theDoc.Rect.Inset(50, 90);
theDoc.Page = theDoc.AddPage();
int theID;
theID = theDoc.AddImageUrl(System.Web.HttpContext.Current.Request.Url.ToString());
while (true)
{
theDoc.FrameRect(); // add a black border
if (!theDoc.Chainable(theID))
break;
theDoc.Page = theDoc.AddPage();
theID = theDoc.AddImageToChain(theID);
}
for (int i = 1; i <= theDoc.PageCount; i++)
{
theDoc.PageNumber = i;
theDoc.Flatten();
}
if (Request.QueryString["DocumentNo"] != null)
{
string dateNow = "(" + DateTime.Now.ToString().Replace("/", "-") + ")";
dateNow = dateNow.Replace(" ", "-");
dateNow = dateNow.Replace(":", "-");
theDoc.Save(Server.MapPath("PDFInvoices/" + Request.QueryString["DocumentNo"].ToString() + dateNow + ".pdf"));
}

theDoc.Clear();