1/14/2013
Diet
Read more: digitaljournal.com/article/341150#ixzz2Htq0xcah
barrons.com/articles/why-edward-thorp-only-owns-berkshire-hathaway-1521547200
ketones via low-carb diet (for example: meat or fish with salad, but no sugar, grains, rice, starchy vegetables)
9/19/2008
IIS hosting
TODO:
- From a PC use the Windows Professional's IIS to host an .aspx page that uses SQL Server Express 2005.
- boutell.com/newfaq/creating/hostmyown.html
- Include some notes & directions howto:
- Open up the IIS window on the PC by doing so: >My Computer >Manage >Services and Applications >IIS
- >Local Disk E: >Inetpub >ftproot (Go here to check the stuff that gets hosted (Thus FTP to here).)
- Then go to http://localhost/ in a browser's address bar to view the test .aspx page
- Etc...
- Take the dynamic IP of our IIS and put it in the browser's address bar to test. (Ex. http://192.168.254.2/Default.aspx)
- Get a static IP from DynDNS.com and add it to the IP input field in mydomainname.com's GoDaddy dashboard. Thus mydomainname.com with GoDaddy will point to the IP of our IIS server hosting PC.
- We are getting an error when our page includes a database stuff: aspspider.com/resources/Resource170.aspx
- Add mydomainname.com to here domains.live.com (What this service does, I do not know yet.)
Much later TODO:
- Set up a mail-server on the said IIS (or activate it if one is included with it)
- Take the DNS settings from Hotmail and add them so email messages to mydomainname.com's domain name get sent to his said domain name (ex. bob@mydomainname.com).
- MX (Mail Exchange) records are used in DNS records (or Zone files) to specify how email should be routed.
Extras
- With IIS7 Rewrite module a website can have a .htaccess file. See hanselman.com/blog/ASPNETMVCAndTheNewIIS7RewriteModule.aspx.
7/11/2008
VB: Regular Expressions, etc...
Regex.IsMatch("subject", "regex") ' Checks if the regular expression ' matches the subject string.
VB: using Controls collection
' Clears textbox controls' content on the form using ' Controls collection. Dim intX As Integer Do While intX < text = "" intx =" intX">
ViewState("UrlReferrer")
Sub Page_Load()
If Page.IsPostBack = False Then
' Store URL Referrer to return to home page.
ViewState("UrlReferrer") = Me.Request.UrlReferrer.ToString()
End If
End Sub
Sub CancelBtn_Click()
' Redirect back to the home page.
Me.Response.Redirect(CType(ViewState("UrlReferrer"), String))
End Sub
ASP confirm
gt-a-s-p:button id="ConfirmOnClick" runat="server" onclientclick="return
confirm('You\'re sure you want to do this?');" text="Launch Airstrike"> lt/ a-s-p:button>
ASP .NET set focus to a control (javascript)
body onload="javascript:document.forms[0].txtFirst.focus();"
7/10/2008
check for DbNull
<_a s p :Label runat="server" ID="Label6" Text='< % # IIF(Typeof( Eval("ShippedDate")) IS DbNull,"No Date",Eval("ShippedDate")) % >' />or
<_%# ((Convert.IsDBNull ...
I am telling ASP to give the picture a height value only if the value in the database is not NULL. I could've done this in the SQL instruction, but I decided to do it inside the Datalist.
<_%# ((Convert.IsDBNull(DataBinder.Eval(Container.DataI tem, "height"))) ? "" : "height = " + DataBinder.Eval(Container.DataItem, "height")) %>Or maybe this for NULLs?:
<_%# Eval("First", "{0}, ") %_>
Or check for NULL in T-SQL:
ISNULL(check_expression, replacement_value)
If 1st is NULL, return 2cnd.
7/03/2008
Search Stored Procedures
SELECT ROUTINE_NAME, ROUTINE_DEFINITION FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_DEFINITION LIKE '%lq_Campaign%' AND ROUTINE_TYPE='PROCEDURE'
Here is another way
Below query you can searcg any table, stored procedure or views what ever has that expression as a column or object name.
SELECT * FROM SYSOBJECTS WHERE ID IN (SELECT ID FROM SYSCOMMENTS WHERE TEXT LIKE ‘%PRODUC%’)
The query produced all the object names--where ever it finds expression like ‘PRODUC‘.
Model View Controller
- Primary goal is to separate the things that change from the things that do not.
- Model is the data representation.
- View is the presentation of the model.
- Controller responds to events and modifies the model.
- Model notifies the views to update the presentation.
5/09/2008
SQL Server 2005 Reports: tips
-
Page Header:
-
TextBox via Expression...:
=Globals.ReportFolder & Globals.ReportName
-
TextBox via Expression...:
-
Page Footer:
-
Page Footer: TextBox via Expression...:
=Format(Globals!PageNumber) & " of " & Format(Globals!TotalPages) & " pages"
-
="Printed by " & User!UserID & " on " & DateTime.Now.ToString()
-
="Execution Time: " & IIF(System.DateTime.Now.Subtract(Globals!ExecutionTime).TotalSeconds < 1, "0 seconds", ( IIF(System.DateTime.Now.Subtract(Globals!ExecutionTime).Hours > 0, System.DateTime.Now.Subtract(Globals!ExecutionTime).Hours & " hour(s), ", "") & IIf(System.DateTime.Now.Subtract(Globals!ExecutionTime).Minutes > 0, System.DateTime.Now.Subtract(Globals!ExecutionTime).Minutes & " minute(s), ", "") & IIf(System.DateTime.Now.Subtract(Globals!ExecutionTime).Seconds > 0, System.DateTime.Now.Subtract(Globals!ExecutionTime).Seconds & " second(s)", "")) )
-
Page Footer: TextBox via Expression...:
-
Body:
-
TextBox via Expression...:
=Format(Sum(Fields!Account.Value), "C0")
(Works if column is numeric data type.) -
Alternate rows by adding the following to the row via Properties > BackgroundColor expression of your detail row:
=IIF(RowNumber(Nothing) Mod 2, "White", "Gainsboro")
-
TextBox via Expression...:
- msdn.microsoft.com/en-us/library/aa337293.aspx
- *en.csharp-online.net/Building_Reports_in_SQL_Server_2005
- *ssw.com.au/Ssw/Standards/Rules/RulesToBetterSQLReportingServices.aspx
- download.microsoft.com/download/1/3/4/134644fd-05ad-4ee8-8b5a-0aed1c18a31e/reporting_services_design.doc
- notethat.blogspot.com/2007/10/reporting-services-tips-tricks-and.html
3/28/2008
SSIS > VS Export wizard: table to Excel
DROP TABLE Query
to the Event Handlers tab or else it will error the second time it is reRun.
SSIS > VS Import wizard for Excel to table:
- Be sure to only checkmark Results$.
- Be sure to Select Delete table option.
- Be sure to Change Results$ name to Destination table name.
- If there is an error, it is often because a row in Excel has a NULL but the table column is NOT NULL (so add a blank to the Excel field).
3/07/2008
ReplaceCommasWithPipes.vbs
' Currently this VBScript is set to replace-commas-with-pipes for every file that is 'in the folder where this VBScript sits: ' Before run it do the following: ' 1. Open VBScript in text editor ' 2. Set the parameters: ' cFolder_Name = "." ' current directory ' cOnlyOneFile = False ' set to True if I want to process only one file with name set below ' cOnlyFileName = "thisfile.csv" ' 3. Place the VBScript into the target folder ' 4. Run it by double-click ' Notes: http://groups.google.com/group/microsoft.public.excel.misc/browse_thread/thread/79ddd204ebb88287/be5d195da9241df9%23be5d195da9241df9 ' ------------------------------------------------------- On Error Resume Next const cFolder_Name = "." ' current directory const cOnlyOneFile = False ' False, So all files in the folder. const cOnlyFileName = "thisfile.csv" ' Uses this if the above was True (only wanted to process 1 file). Set oFSO = CreateObject("Scripting.FileSystemObject") ' Get folder: Set oFolder = oFSO.GetFolder(cFolder_Name) If oFolder Is Nothing Or Err.Number <> 0 Then MsgBox "Can't get a folder for search files. " + vbCRLF + "Please check the folder name." + vbCRLF + Err.Description, vbCritical, "Fatal error!" ' I will probably comment this out when this VBScript runs automatically as a scheduled job. End If Set oFiles = oFolder.Files If Err.Number <> 0 Or oFiles Is Nothing Then MsgBox "Can't get a list of files of folder." + vbCRLF + "" + vbCRLF + Err.Description, vbCritical, "Fatal error!" ' I will probably comment this out when this VBScript runs automatically as a scheduled job. End If Cnt = CInt(0) For Each oFile In oFiles If oFSO.GetExtensionName(oFile.Name) = "csv" Then ' Checks for "csv" file extension. If (cOnlyOneFile And (oFile.Name = cOnlyFileName)) Or (Not cOnlyOneFile) Then Call ReplaceSymbols(oFile.Name) Cnt = Cnt + 1 End If End If Next Senmail() MsgBox "Replacing is done. Total number of files had been processed: " + CStr(Cnt), vbExclamation, "Message..." ' I will probably comment this out when this VBScript runs automatically as a scheduled job. ' cleanup Set oFiles = Nothing Set oFSO = Nothing ' Find-and-replace: Sub ReplaceSymbols(oFileName) ' AKA "File.Name". If oFSO.FileExists(oFileName) Then Set oTextFile = oFSO.OpenTextFile(oFileName, 1, False) sFileContents = oTextFile.ReadAll oTextFile.Close Set oRegEx = CreateObject("VBScript.RegExp") With oRegEx .Global = True .IgnoreCase = False .Pattern = "," ' Or vbTab or "|" etc... sFileContents = .Replace(sFileContents, "|") ' .Pattern = "\|" ' reverse replacing ' sFileContents = .Replace(sFileContents, ",") End With Set oNewFile = oFSO.CreateTextFile(oFileName, True) ' Maybe oNewFile is not needed--it just could have been called oTextFile. oNewFile.Write sFileContents oNewFile.Close End If End Sub ' NOTE: This first way would only work on my PC, not on the other user's PCs; so I must use the second snippet, Senmail(), at the bottom. NOTE: If I made the changes marked "future testing" this might work. ' Send email to Jon Doe. --If the PC this runs on is not set right, this email will not get sent. 'Set oMessage = CreateObject("CDO.Message") 'oMessage.From = "Generated automatically for AWARE" ' NOTE: If future testing: Comment this out. 'oMessage.To = "jon.doe@jd.com,jon.doe2@jd.com" ' NOTE: If future testing: Should be ";". 'oMessage.Subject = "AWARE: Extracts done." 'oMessage.Sender = "jon.doe@jd.com" ' NOTE: If future testing: Comment this out. 'oMessage.TextBody = "AWARE: Commas replaced with pipes." 'oMessage.Send ' NOTE : Is using MS Outlook API to send e-mails. So check If MS Outlook installed on a workstation before a using of this script. Sub Senmail() Set objOutlook = CreateObject("Outlook.Application") Set objOutlookMsg = objOutlook.CreateItem(0) With objOutlookMsg ' This line caused it not to even popup warning, so leave it off: .From = "jon.doe@jd.com " ' "Generated automatically for AWARE " .To = "jon.doe@jd.com; jon.doe2@jd.com; jon.doe3@jd.com; jon.doe4@jd.com" .Subject = "AWARE: Extracts done." ' This line caused it not to even popup warning, so leave it off: .Sender = "jon.doe@jd.com" ' NOTE: jon.doe2's email is automatically inserted here because it is sent from here Outlook. .Body = "AWARE: Commas replaced with pipes. [Note: This message was generated and sent automatically.]" .Send End With Set objOutlookMsg = Nothing Set objOutlook = Nothing End Sub
3/06/2008
Create SSIS to copy tables
An SSIS to copy tables from a Source to a Destination. Directions:
- From Start, select SQL Server Business Intelligence Development Studio
- File
- New Project…
- Project types: Business Intelligence Projects
- Integration Services Project…
- Click “OK”
- New Project…
- Toolbox
- Drag "Transfer SQL Server Objects Task" to "Control Flow" tab's pane.
- Right-click choose Edit…
- Objects
- SourceConnection ‹New connection…› = NWDSQL
- SourceDatabase = NIS_empl_wage
- DestinationConnection ‹New connection…› = TESTSQL
- DestinationDatabase = NIS_empl_wage
- CopyData = True
- ExistingData = Replace (so not append (dup errors))
- ObjectsToCopy (expand)
- CopyAllTables = True (so not sprocs)
- Note: Leave all other options False. Ex., Table Options—Can leave all these False because it will just move data so Destination’s Primary Keys will remain.
- Objects
- Click “OK”
- Right-click choose Edit…
- Drag "Transfer SQL Server Objects Task" to "Control Flow" tab's pane.
- Save and Run
Note 1: Your Properties for the Transfer SQL Server Objects Task will now look like this:
- CopyAllTables = True (so not sprocs)
- CopyData = True
- DestinationConnection = TESTSQL
- DestinationDatabase = NIS_empl_wage
- ExistingData = Replace (so not append (dup errors))
- SourceConnection = NWDSQL
- SourceDatabase = NIS_empl_wage
Note 2: A DB "restore" by the DBA would nix Destination tables that do not exist in Source tables; but not this technique.
2/22/2008
CASE: This way (3) NULLs get put in tbl if data is blank.
command = New SqlCommand("INSERT INTO tblFoo (UIAcctNum, WorkZip, CheckRouteDesc, Agency, Division, RUN, Rpt_Unit_RUNDesc, StartDate,EndDate ,CheckRouteCode, Rpt_Unit_RUNDesc__old,NAICS) " & _ " VALUES (@UIAcctNum, @WorkZip, @CheckRouteDesc, @Agency, @Division, @RUN, " & _ "CASE WHEN ltrim(@Rpt_Unit_RUNDesc) = '' THEN NULL ELSE @Rpt_Unit_RUNDesc END, " & _ "@StartDate, " & _ "CASE WHEN ltrim(@EndDate) = '' THEN NULL ELSE @EndDate END, " & _ "@CheckRouteCode, " & _ "CASE WHEN ltrim(@Rpt_Unit_RUNDesc__old) = '' THEN NULL ELSE @Rpt_Unit_RUNDesc__old END, " & _ " CASE WHEN ltrim(@NAICS) = '' THEN NULL ELSE @NAICS END)", connection) ' This way (3) NULLs get put in tbl if data is blank.
12/10/2007
SQL notes
SELECT * FROM ES202_RUN_LKP WHERE EndDate BETWEEN CAST('01/01/2005' AS DATETIME) AND CAST('01/11/2008' AS DATETIME)
SELECT DISTINCT * INTO ##temp3 from ##temp2 --Use this if I want to INSERT rows AND create the destination table.
WHERE ##temp1.Area <> ##temp2.Area -- The 'WHERE <>' stops a cartesian join.
SELECT * INTO ##temp3 FROM (SELECT * FROM ##temp1 UNION SELECT * FROM ##temp2) un
strSQL = "IF OBJECT_ID('tblTempNIS_Qtrly_SumByRUN_and_crc', 'U') IS NOT NULL DROP TABLE tblTempNIS_Qtrly_SumByRUN_and_crc" ' This is not really a temp table because no #; so must DROP. It's a helper table. Couldn't use a temp because mData's Clear lose the data for the next query's use of it. ' The ", 'U' " is optional; it just insures that the object is a user table and not, for example, a sproc or other type of object.
-
' To get all information about the @@Error value that is returned in the output parameter ' From Master database ' SELECT * FROM sysmessages WHERE Error = 2627 ' type value in rdoQy(3) here
--NWDSQL.BmrkSource.PendingPublish is empty for 2003-2004. Thus do this to populate it with rows from the other table: INSERT INTO BmrkSource.dbo.PendingPublish SELECT NEArea,IdentifierCode,EndDate,NumberOfPeople,Week,ItemCodeID,Ratio --Note: Published has 1 extra column at the end so I must list these out. FROM NELausData.dbo.Published WHERE NELausData.dbo.Published.EndDate LIKE '2004%' OR NELausData.dbo.Published.EndDate LIKE '2003%'
- The INNER JOIN returns all rows from both tables where there is a match. If there are rows in first table that do not have matches in second table, those rows will not be listed.
- The LEFT JOIN returns all the rows from the first table, even if there are no matches in the second table. If there are rows in first table that do not have matches in second table, those rows also will be listed.
- The RIGHT JOIN returns all the rows from the second table, even if there are no matches in the first table. If there had been any rows in second table that did not have matches in first table, those rows also would have been listed.
- SQL Server is phasing out text, ntext, and image. There’s no way to know how long SQL Server will support the older data types. Upgrade legacy applications to varchar, nvarchar, and varbinary.
11/22/2007
How to get a DB and send it....
You can backup the DB from the server and then restore it on your local machine with installed MS SQL Server 2000. Then you can change or delete any pruned info from the DB on your local machine. Then you can backup the modified DB again and send that backup file (*.bak file). You can send this file with Gmail. There is about 3Gb available space.
- How to backup...
- Open Enterprise Manager
- Select source DB
- Right click on the selected DB. Select All Tasks->Backup Database... from the popup menu.
- Select File and filegroup and add destination file name in the Backup dialog.
- Press OK
- How to restore...
- Open Enterprise Manager
- Select Databases node
- Right click on this node. Select All Tasks->Restore Database... from the popup menu.
- Type database name in the Restore as database textbox
- Select Restore From Device
- Press Select Device
- Add backup file name
- Press OK
- In the Options tab check file pathes where your database will be restored.
- Press OK
- Select File and filegroup and add destination file name in the Backup dialog.
- Press OK
9/27/2007
Excel: compare two Worksheets
Excel Macro
http://exceltip.com/st/Compare_two_worksheets_using_VBA_in_Microsoft_Excel/477.html
Compares the 2 Worksheets and pops up a workbook with the differences:
Steps:
>Tools > Macro >Macros >Run
Excel Function
Function for comparing data: http://office.microsoft.com/en-us/excel/HP100625641033.aspx?pid=CH100645341033
Here's the Excel formula: =Exact(ColumnRow,ColumnRow)
An example: =EXACT(G5,P5)
[First put both worksheets on the same worksheet, side by side.]
If the result is True data matches; if False data does not match
Also, I was told there is a way to recieve as output each row that was different using a "Filter".
8/31/2007
SQL compare two tables
Select col_a,col_b from table1
where not exists
(select * from table2
where table1.col_a = table2.col_a and
table1.col_b = table2.col_b)
Repeat for table2.
further notes: --http://windowsitpro.com/Articles/ArticleID/14368/14368.html?Ad=1 --http://webmasterworld.com/databases_sql_mysql/3241540.htm
Here is a way of comparing 2 tables that I tried at work:
-- DROP my new temp table if exists: DROP TABLE ##EricsTempUnionOfMonthlyAndBiweekly -- UNION the monthly & biweekly tbls into a temp table: SELECT * INTO ##EricsTempUnionOfMonthlyAndBiweekly FROM (SELECT * FROM NISTempLowLevelMonthly UNION SELECT * FROM NISTempLowLevelBiweekly) un -- Verify it: SELECT * FROM ##EricsTempUnionOfMonthlyAndBiweekly --18347rows, yes this was a UNION of monthly & biweekly tables. -- LEFT OUTER JOIN which means gives me the differences: SELECT DISTINCT * FROM ##EricsTempUnionOfMonthlyAndBiweekly LEFT OUTER JOIN NISTemp_Qtrly_Detail ON NISTemp_Qtrly_Detail.SocSecNumber = ##EricsTempUnionOfMonthlyAndBiweekly.SocSecNumber -- 72573 rows
7/20/2007
Debug sproc [MSSQL stored procedures] in VS
( Source: http://aspalliance.com/1131_Understanding_Object_Pooling_in_Microsoft_NET )
In VS at the Sever Explorer pane I right-click on my data connection that I added and select Modify Connection. Then in the Modify Connection dialog I clicked Advanced... and then in the Advanced Properties dialog I changed Pooling from True to False. Now it works.
Also, in the configuration file, the Enable SQL Server debugging must be checked. Also, I have to add cmd.CommandTimeout=1800
to the VB's sproc area else it will time-out while clicking thru the sproc in the debugger.
But, when not debugging, in order to get the app to run to completion without crashing with the error Error while executing 'a batch cmd' at line 0 , I have to uncheck Enable SQL Server debugging and set Pooling back to True. --Because not pooling the connections hurts performance.
(Summary: You do the above to VS so that you can step through,and see, the database while debugging the code of an app in VS.)
7/18/2007
To export DTS package, do the following:
- Open MS SQL Server Enterprise Manager
- Go to Local Packages
- Open some DTS Package
- In the DTS Package window from menu select item Package->Save As...
- In the Save DTS Package dialog
- in the Location field select Structured Storage File
- in the File Name field set destination path of saved file
- Press OK button
6/20/2007
Server 2000: Query Analyzer Tips & Tricks
6/19/2007
Getting .dll into Registry
- Download the file (MSRDO20.zip) to your desktop
- Unzip the content of the file (a file called MSRDO20.DLL) to your desktop
- Right now you should have a new file called MSRDO20.DLL that resides on your desktop
- Copy this file to your Windows System Folder; this folder is usually found inside your 'C:\Windows' folder. It is called 'C:\Windows\System' or 'System32'...
- Go to 'Start Menu' and choose 'Run'
- A new window titled 'Run' will open; type the line 'regsvr32.exe msrdo20.dll' and hit 'Enter'.
- A message will show up stating that the registration was successful.
6/09/2007
Visual Studio Short-cuts
Most of the time, you will Step Into or Step Over commands in your stored procedures. The commands below apply to a single T-SQL line:
- Step Into (F11): Use to single step through your code. (Move the yellow arrow down one statement.)
- Step Over (F10): Useful if you have lines of code that perhaps modify data or call other procedures that you don't care about while debugging. For example, you may want to skip code that performs auditing.
- Step Out (SHIFT+F11): Execute the rest of the stored procedure without pause.
- Run to Cursor (CTRL+F10): Position the cursor to a point in your code and then hit CTRL-F10 to execute all code up to that point.
- Continue or Start Debug or Run (F5): Start Debug. Or resumes execution until completion or until the next breakpoint.
- Toggle Bookmark (CTRL+K)
- Help (F1)
When you provide a summary of the class using XML comments, your class displays documentation about itself in appropriate places within Visual Studio, such as in the List Members box. Open the List Members box by selecting Edit | Intellisense | List Members from the main menu bar or by clicking the Display an Object Member List icon on the Text Editor toolbar.
Command Window debugging: Getting Values
To see the value of your variable whilst in Debug mode, use the "Command Window" (View >Other Windows >Command Window). Enter this: ? myVariableName
http://www.ondotnet.com/pub/a/dotnet/excerpt/vshacks_chap1/index.html
5/18/2007
SQL: Bulk import
Bulk import (save file.txt as csv): LOAD DATA INFILE 'file.txt' INTO TABLE 'tblFoo' (col1, col2, col3)
or
BULK LOAD IMPORT ('c:\file.txt') INTO TABLE 'tblFoo' (col1, col2, col3)
5/11/2007
SQL Server 2000: make table backup with DTS
- Right-click the table
- choose Export Data
- Choose a destination
- Server: "nwdsql" and Database: NELausData
-
copy table(s) -
UserXRef"_bkup" (Destination)
Done, then refresh explorer to view.
11/26/2006
Install Google Search API Into Visual Studio
- Get the Google API and unzip. Import GoogleSearch.wsdl to the Project root.
- Right-click on the Project root.
- Add Web Reference
- Then type in the URL: http://localhost:1574/projectname/GoogleSearch.wsdl or http://foo.com/GoogleSearch.wsdl
- Add Web Reference
Then you should see an App_WebReferences folder in your Project. And then a folder in that called localhost. And then files GoogleSearch.discomap and GoogleSearch.wsdl in that.
11/19/2006
Load a Control into Visual Studio
- Right-click on toolbar and "Choose Items"
- Then browse and go to your /Controls/ folder
- Then click on it and open
- Then click "OK"
Then it will be on your toolbar and there will be a Reference to it in your /Bin/