Posts

Showing posts from January, 2015

Searching for text in a database with ApexSQL

While http://www.red-gate.com/ provides some good search functionality (for FREE) for looking through the objects for reference code, I used to use the " FindMyData_String " procedure below (I would give a reference and amend the post if I could find where it came from). This was a blunt tool, which I never really changed or modified and only pointed me in the right direction to where the data might be. Now I use http://www.apexsql.com/sql_tools_search.aspx ; this is FREE and awesome; you can select the database, tables, type of columns, dateformate etc etc, and it is very fast. just download it and check it out on your dev machine. It will tell you the column and the value so you can see exactly what you are looking for. Blunt Tool for searching all tables ALTER PROCEDURE [dbo].[FindMyData_String] @DataToFind NVARCHAR(4000), @ExactMatch BIT = 0 AS SET NOCOUNT ON DECLARE @Temp TABLE(RowId INT IDENTITY(1,1), SchemaName sysname, TableName sysname, ColumnName SysNa

Organizing SQL Procedures and Functions like Oracle Packages (ish)

Oracle's package syntax is a nice way of packaging sets of functions/ procedures etc, however when a package is updated, that brings everything down. If you have a cached JDBC connection, that causes even more problems as you have to recycle the connections. On SQL, there is no package, and thus you could end up with hundreds if not thousands of little procedures and functions. A good trick is to use schemas to organize them: this example will return 2 queries; could also use input output parameters create schema [myutils]; create procedure [ myutils ].[aFewQueries] @someid int output ,@someid2 int output as begin --  set nocount on; added to prevent extra result sets from interfering with SELECT statements. set nocount on; -- Insert statements for procedure here select * from table1 where id = @someid; select * from  table2_other where  id = @someid ;  select  @someid2  = 5; end go In ColdFusion you could neatly call this like so: <cfstoredpr

New Query Window in Microsoft SQL Server Management Studio Defaults/ Template

When you have those pesky common commands you have to use in almost all windows, you can change the default empty template like so Open (or wherever the installation is) C:\Program Files\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\SqlWorkbenchProjectItems\Sql\Sqlfile.SQL And add in your defaults; my usual is: select @@SERVERNAME, @@SERVICENAME,@@VERSION, current_user, SYSTEM_USER

MX Checking and Email Validation

Whilst encountering people inputting technically correct email address, but generally not correct (there is no gmail.com.au etc), was looking around for an MX validation, particularly important for eCommerce guest checkouts when receipt emails are just not arriving. Dominic Sayers example in PHP (ported in Java also) seems to be one of the top ones, but kept replying with invalid MX records (probably my fault) and it is written PHP, which didn't suit my needs, see https://code.google.com/p/isemail/ Also attempted this guys implementation in ColdFusion of the above one, but didn't quite work for me either:  https://gist.github.com/JamoCA/72cdcb77246ea0ee5820 When checking how the PHP was actually written; noticed a function called dns_get_record in PHP, haven't seen that one in ColdFusion, had a root round, found Pete Freitag example at http://www.petefreitag.com/item/487.cfm Modifed that slighlty for my own needs, using Google's Public DNS ; ended up with below (

Mail from applications and improved deliverability (SPF Records DKIM keys)

Sometimes you have to send a mail from a server that is not your mail server (ie an application server). To make sure big ISPs know you are doing the right thing, you have to set up SPF records - see  http://www.openspf.org/SPF_Record_Syntax This will then ensure that your application server is permitted to send on behalf of the proper mail domain. Most common is if you use a EDM provider; there is a good write up here at Campaign Monitor  http://help.campaignmonitor.com/topic.aspx?t=88

Bulk import on SQL with Format File

Quick fire way to get new data into a SQL table using bulk load: C:\>bcp thedatabase.dbo.thetable format nul -t -n -f thetable.fmt -U  yourusername  -P yourpassword USE thedatabase GO BULK INSERT thetable FROM 'C:\thetabelnewdata.dat' WITH (FORMATFILE = 'C:\thetable.fmt'); GO SELECT * FROM thetable go How does the .fmt file look? ( http://msdn.microsoft.com/en-us/library/ms191516.aspx ) Lots of different values, but here is one example 10.0 9 1 SQLCHAR 0 1 "\"" 0 first_double_quote SQL_Latin1_General_CP1_CI_AS 2 SQLCHAR 0 20 "\",\"" 1 ip_from "" 3 SQLCHAR 0 20 "\",\"" 2 ip_to "" 4 SQLCHAR 0 2 "\",\"" 3 country_code SQL_Latin1_General_CP1_CI_AS 5 SQLCHAR 0 64 "\",\"" 4 country_name SQL_Latin1_General_CP1_CI_AS 6 SQLCHAR 0 128 "\",\"" 5 region_name SQL_Latin1_General_CP1_CI_AS 7 SQLCHAR 0 128 "\",\"

Easter Egg Google Roll (ish)

Found this online, then forgot but used it for a funny treat on a sales system when they hit a huge target <style> .barrel_roll { -webkit-transition: -webkit-transform 4s ease; -webkit-transform: rotate(360deg); -moz-transition: -moz-transform 4s ease; -moz-transform: rotate(360deg); -o-transition: -o-transform 4s ease; -o-transform: rotate(360deg); transition: transform 4s ease; transform: rotate(360deg); } </style> <script> $(function() { /* code here */ document.getElementsByTagName('body')[0].className='barrel_roll'; }); </script> Thanks to whoever wrote it first; sorry I can't remember where it came from.