Quick and Easy method:
Response.Clear
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader "Content-Disposition", "inline;filename=requests.csv"
'Response.AddHeader "Content-Disposition", "attachment;filename=requests.csv"
Dim header : header = ""
prefix = false
Dim field
for each field in rs.Fields
if(prefix) then
header = header & ","
end if
header = header & field.Name
prefix = true
next
Response.Write header & vbCRLF & rs.GetString(,,",",,"")
Response.End
Tuesday, July 31, 2007
IF-THEN-ELSE logic in a SELECT statement
SELECT ename, CASE WHEN sal = 1000 THEN 'Minimum wage'
WHEN sal > 1000 THEN 'Over paid'
ELSE 'Under paid'
END AS "Salary Status"
FROM emp
WHEN sal > 1000 THEN 'Over paid'
ELSE 'Under paid'
END AS "Salary Status"
FROM emp
Monday, July 23, 2007
3 Ways to Reload Page with JavaScript
window.location.reload()
history.go(0)
window.location.href=window.location.href
Friday, July 20, 2007
JavaScript Dynamic Document Creation in New Windows
newtext = document.forms.mainForm("MyTextAreaElement").value;
newwindow = window.open();
newdocument = newwindow.document;
newdocument.write(newtext);
Tuesday, July 17, 2007
Object doesn't support this property or method: 'EOF'
Happens when you forgot to use SET when assigning an object to a variable, e.g.:
set conn = CreateObject("ADODB.Connection") conn.open "<connection string>" rs = conn.execute("SELECT columns FROM table") if not rs.eof then ' error here ' .. |
The line starting with "rs = " should start with "SET rs = " ...
Thursday, July 5, 2007
Using Exists statement in If statements
You'd think there'd be a more elegant way to do this, but...
IF NOT EXISTS(
SELECT TOP 1 1 FROM mytable WHERE myid = @myid
)
BEGIN
...do stuff
END
Monday, July 2, 2007
Annoying Issue with Float and IsNumeric
Warning: When you use IsNumeric in VBScript, it will allow commas to pass. If you don't remove those commas from the string and pass it to a T-SQL procedure which expects a Float, you will get an error "
Error converting data type varchar to float."
Subscribe to:
Posts (Atom)