Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

j

« Newer Snippets
Older Snippets »
Showing 1-8 of 8 total  RSS 

Financial Year Calculation

select (case when
datepart(mm,reqDate) between 7 and 12 then
datename(yy,reqDate) + '-' + datename(yy,dateadd(yy,1,reqDate))
else
datename(yy,dateadd(yy,-1,reqDate)) + '-' + datename(yy,reqDate)
end),
reqDate
from request
order by 1, 2

Vbscript Array sort in alphabetical order

// sort vbscript array

<%
dim arrSortOut(8)
arrSortOut(0)="xCount"
arrSortOut(1)="zExec"
arrSortOut(2)="yFinance"
arrSortOut(3)="HR"
arrSortOut(4)="IT "
arrSortOut(5)="!aaaLegal"
arrSortOut(6)="Liberman"
arrSortOut(7)="Martha"
arrSortOut(8)="Regis"

for x=0 to 8
response.write arrSortOut(x)&"<br>"
next

response.write "<br>"

for i = UBound(arrSortOut) - 1 To 0 Step -1
    for j= 0 to i
        if arrSortOut(j)>arrSortOut(j+1) then
            temp=arrSortOut(j+1)
            arrSortOut(j+1)=arrSortOut(j)
            arrSortOut(j)=temp
        end if
    next
next 


for x=0 to 8
response.write arrSortOut(x)&"<br>"
next

%>

CSS - Show Application Icon next link

// This CSS code will show the appropriate icon next to a HREF link

<!DOCTYPE html>

<head>
<style type="text/css">
p {font: normal 1em/1.2em tahoma;}

/* all A tags whose HREF attribute ends in .pdf */
a[href$='.pdf'] { 
	padding-left: 18px;
	background: transparent url(pdf.gif) no-repeat center left;
}

/* all A tags whose REL attribute = pdf */
a[rel='pdf'] { 
	padding-left: 18px;
	background: transparent url(pdf.gif) no-repeat center left;
}

/*  all A tags whose REL attributes has the string pdf inside */
a[rel*='pdf'] { 
	padding-left: 18px;
	background: transparent url(pdf.gif) no-repeat center left;
}


/* all A tags whose HREF attribute starts with mailto: */
a[href ^="mailto:"] {
	padding-left: 18px;
    background: transparent url(mailto.gif) no-repeat center left;
   
}

/* all A tags whose CLASS attribute is popup */
a[class ="popup"] {
	padding-left: 18px;
    background: transparent url(popup.gif) no-repeat center left;
}


a[href$='.doc'] { 
	padding-left: 18px;
	background: transparent url(doc.gif) no-repeat center left;
}
a[href$='.xls'] { 
	padding-left: 18px;
	background: transparent url(xls.gif) no-repeat center left;
}
a[rel ~='external'] {
	padding-left: 18px;
	background: transparent url(external.gif) no-repeat center left;
}
</style>
</head>
<body>
<p><a href="mailto:x@x.com">email</a></p>
<p><a class="popup" href="#">pop up</a></p>
<p><a href="test.doc">word</a> </p>
<p><a href="test.xls">excel</a></p>
<p><a rel="external" href="http://www.test.com">website</a></p>
<p><a href="test.pdf">pdf</a></p>
<p><a rel="pdf" href="test">pdf2</a></p>
<p><a rel="xxpdfxx" href="test">pdf3</a></p>



</body>
</html>

Write all ASP page variables

// description of your code here

<%
  Response.Write "Server Variables" & "<br><br>"
For Each strName in Request.ServerVariables
  Response.Write strName & " - " & Request.ServerVariables(strName) & "<BR>"
Next

  Response.Write "Session Variables" & "<br><br>"
For Each strName in Session.Contents
  Response.Write strName & " - " & Session.Contents(strName) & "<BR>"
Next

  Response.Write "Form Variables" & "<br><br>"
For Each strName in request.form
  Response.Write strName & " - " & request.form(strName) & "<BR>"
Next

  Response.Write "String Variables" & "<br><br>"
For Each strName in request.querystring
  Response.Write strName & " - " & request.querystring(strName) & "<BR>"
Next
%>

Clipboard functionality

// description of your code here

<SCRIPT LANGUAGE="JavaScript">

function ClipBoard() 
{
Copied = DescriptionText.createTextRange();
Copied.execCommand("Copy");
}

</SCRIPT> 

<TEXTAREA ID="DescriptionText">copy this text</textarea>
<img src="copy.gif" align=absMiddle border=0 onClick="ClipBoard();">

Simple FSO directory file listing

// simple browsing tool

<%

dim aryURL, URLvar
aryURL = Split(Request.ServerVariables("SCRIPT_NAME"), "/", -1, 1)
URLvar = aryURL(ubound(aryURL))

if request.querystring("sPP")<>"" then 
	
	sPP=request.querystring("sPP") & "\"
	ParentVar="<a href=""#"" onClick=""history.go(-1)"">Parent Directory</a><br><br>" & vbCrLF
else
	sPP = "\\serverlocation\"
end if

	
	Set fso = CreateObject("Scripting.FileSystemObject")
	Set f = fso.GetFolder(sPP)  
	Set fc = f.Files 
	Set ff = f.SubFolders 
	For Each f1 in ff	
	  HeaderVar=HeaderVar& "<a href=""" & URLvar & "?sPP=" & sPP & f1.name & """>" & f1.name & "</a> &nbsp;|&nbsp;" & vbCrLF
	Next  
	For Each f1 in fc
	  SubHeaderVar=SubHeaderVar& "<a href=""" & sPP & f1.name & """>" & f1.name & "</a> <br>" & vbCrLF
	Next  
	Set ff = nothing
	Set fso = nothing
	Set f = nothing
	Set fc = nothing


response.write ParentVar
if HeaderVar<>"" then response.write "<b>Folders" & vbCrLF & "<br><br>&nbsp;|&nbsp;" & vbCrLF & HeaderVar & "</b><br><br>" & vbCrLF
if SubHeaderVar<>"" then response.write "<b>Files</b>" & vbCrLF & "<br><br>" & vbCrLF & SubHeaderVar & vbCrLF

%>




SQL server ASP database test

// basic sql server database asp code test

<%
str_ConnectionString = "Provider=SQLOLEDB;Data Source=servername;Initial Catalog=database;User Id=user;Password=pwd;"
Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open str_ConnectionString

set rs = Server.CreateObject("ADODB.recordset")
strSQL="select * from tablename"

rs.Open strSQL, oConn

do until rs.EOF
	for each x in rs.Fields
		response.write x.value & "|"
	next
	rs.MoveNext
	response.write "<br>"
loop	

rs.Close

oConn.Close
set oConn = Nothing
%>

sql server backup script for all user databases

// This code will create new backup locations on disk on a daily / weekly / yearly basis

-- Declare variables

declare @count int, @max int, @day varchar(10), @path varchar(1000), @dbname varchar(55)
declare @device varchar(255), @physical varchar(1255), @lastbackup smalldatetime

-- Set count to start at database ID +1 
-- master	1
-- tempdb	2
-- model		3
-- msdb		4
-- pubs		5
-- Northwind	6

set @count = 7

-- Set maximum no of databases on server

--set @max = (select count(*) from master..sysdatabases) +1
set @max = 12

-- Set backup path

set @path='D:\SQL\backups\'

-- Get unique cycle number
-- For weekly cycle - datepart(dw,getdate())
-- For monthly cycle - datepart(dd,getdate())
-- For yearly cycle - datepart(dy,getdate())

set @day=datepart(dw,getdate())

-- While the starting number of databases is smaller than the maximum number
-- of databases:
-- 1.	Check if there is already a backup device made for this
-- day of the cycle. If there isn't create the device.
-- 2.	See if a backup has already been done for this day of the cycle. If 
-- it hasn't do a full backup, otherwise do a differential backup.
-- 3.	Repeat for next database.

while (@count < @max)
begin
	
	set @dbname = (select [name] from master..sysdatabases where dbid=@count)
	set @device=@dbname + '_' + @day
	
	if (select count(*) from master..sysdevices where name = @dbname + '_' + @day)=0 begin
		set @physical=@path+@device + '.bak'
		EXEC sp_addumpdevice 'disk', @device, @physical
	end
	
	begin
	
		set @lastbackup=(select max(backup_finish_date) 
		from msdb.dbo.backupmediafamily, msdb.dbo.backupset
		where msdb.dbo.backupset.media_set_id=msdb.dbo.backupmediafamily.media_set_id
		and logical_device_name=@device
		)
		
		if datepart(dd, @lastbackup)!=datepart(dd,getdate()) begin
			BACKUP DATABASE @dbname TO @device WITH INIT
		end
		else begin
			BACKUP DATABASE @dbname TO @device WITH DIFFERENTIAL
		end 
	
	end  
	
	set @count = @count + 1  

continue 
break

end 


« Newer Snippets
Older Snippets »
Showing 1-8 of 8 total  RSS