<feed xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns="http://www.w3.org/2005/Atom" xml:lang="en-US">
    <title>Roy Ashbrook</title>
    <link rel="self" type="application/atom+xml" href="http://www.drowningintechnicaldebt.com/RoyAshbrook/Atom.aspx" />
    <subtitle type="html">let go or be dragged</subtitle>
    <id>http://www.drowningintechnicaldebt.com/RoyAshbrook/Default.aspx</id>
    <author>
        <name>Roy Ashbrook</name>
        <uri>http://www.drowningintechnicaldebt.com/RoyAshbrook/Default.aspx</uri>
    </author>
    <generator uri="http://subtextproject.com" version="Subtext Version 2.1.2.2">Subtext</generator>
    <updated>2013-04-05T00:13:17Z</updated>
    <entry>
        <title>How Heroku made me sad today=(</title>
        <link rel="alternate" type="text/html" href="http://www.drowningintechnicaldebt.com/RoyAshbrook/archive/2013/04/05/how-heroku-made-me-sad-today.aspx" />
        <id>http://www.drowningintechnicaldebt.com/RoyAshbrook/archive/2013/04/05/how-heroku-made-me-sad-today.aspx</id>
        <published>2013-04-05T00:13:17Z</published>
        <updated>2013-04-05T00:13:17Z</updated>
        <content type="html">&lt;p&gt;Yes, &lt;a title="Heroku Happiness!! Forget your servers. Focus on your code!" href="https://www.heroku.com/" target="_blank"&gt;Heroku&lt;/a&gt; made me sad today. &lt;a title="Heroku Happiness!! Forget your servers. Focus on your code!" href="https://www.heroku.com/" target="_blank"&gt;Heroku&lt;/a&gt;!? What?! I can hear you saying it! =P Fortunately I was just coming down off of a fun trip after refreshing myself on the &lt;a title="Online Academy for Coders!" href="http://www.codecademy.com/" target="_blank"&gt;Codeacademy&lt;/a&gt; ruby course. Really nothing there if you already use ruby quite a bit, but I haven’t written any ruby in a couple years and it’s always nice to remember how pleasant that language is to work in. That ruby high is all that kept me plugging away at putting &lt;a title="Dex! The Super Downloader for EXEs. Ok, well it's not super, but it downloads them!" href="http://www.drowningintechnicaldebt.com/RoyAshbrook/archive/2013/04/04/appharbor-and-dealing-with-annoying-firewall-rules.-p.aspx"&gt;dex’s&lt;/a&gt; evil twin ruby brother ‘fwad’ out on &lt;a title="Heroku Happiness!! Forget your servers. Focus on your code!" href="https://www.heroku.com/" target="_blank"&gt;Heroku&lt;/a&gt;. But first… how did &lt;a title="Heroku Happiness!! Forget your servers. Focus on your code!" href="https://www.heroku.com/" target="_blank"&gt;Heroku&lt;/a&gt; make me sad? Well FIRST-first, a little backstory.&lt;/p&gt;  &lt;p&gt;Lately I have been doing a lot of research into cloud providers and looking at various hosted solutions for all sorts of things. So fiddling with these two services over the last couple of days gave me some time to both play with ruby and play with &lt;a title="Heroku Happiness!! Forget your servers. Focus on your code!" href="https://www.heroku.com/" target="_blank"&gt;Heroku&lt;/a&gt; and &lt;a title="App Harbor; Find a port in the storm for your .NET apps!" href="https://appharbor.com/" target="_blank"&gt;AppHarbor&lt;/a&gt;, two pretty popular application hosting/cloud services. I originally had the idea used for dex in ruby. I wrote a local client in ruby that did everything except stream the data in a response. I say “everything” but it should be in quotes the first time as well because I just wrote something simple that would download a file and write it to disk. On a whim, I also thought “hey, why not have it gzip the data as well?” So that’s what I wrote. In fact, here is the local client in all of it’s glory:&lt;/p&gt;  &lt;pre class="csharpcode"&gt;require &lt;span class="str"&gt;"open-uri"&lt;/span&gt;
require &lt;span class="str"&gt;"zlib"&lt;/span&gt;
url = &lt;span class="str"&gt;'http://somesite.with/an/exe/todownload/somefile.exe'&lt;/span&gt;
gzf =  &lt;span class="str"&gt;'c:\temp\somefile.exe.gz'&lt;/span&gt;
open(url) { |rf| #open remote file
  File.open(gzf, &lt;span class="str"&gt;'w+b'&lt;/span&gt;) { |lf| #open local file/stream
    Zlib::GzipWriter.open(lf) { |gz| #open gzipper on local file/stream
      gz.write(rf.read) #write the compressed data
    }
  }
}&lt;/pre&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;p&gt;Not too glorious, eh? Well it was meant to be really really simple. I think I spent like 60 minutes getting ruby installed and writing this little dealio. It worked fine and thus began my campaign to somehow promote it, as a web app, to &lt;a title="Heroku Happiness!! Forget your servers. Focus on your code!" href="https://www.heroku.com/" target="_blank"&gt;Heroku&lt;/a&gt;. I already had an account from when they were in beta, how hard could it be? Well, apparently for someone who works primarily on windows, without git, and without normal ruby DEV tools installed, it’s a bit of a pain. Now, I will say that it isn’t really &lt;a title="Heroku Happiness!! Forget your servers. Focus on your code!" href="https://www.heroku.com/" target="_blank"&gt;Heroku&lt;/a&gt;’s fault that I was somewhat ignorant of what I wanted at the time. But in my defense the first thing I did was try and get a simple hello world site setup as described in their Getting Started with Ruby on &lt;a title="Heroku Happiness!! Forget your servers. Focus on your code!" href="https://www.heroku.com/" target="_blank"&gt;Heroku&lt;/a&gt; tutorial here: &lt;a href="https://devcenter.heroku.com/articles/ruby"&gt;https://devcenter.heroku.com/articles/ruby&lt;/a&gt;. Now, I’m not going to rehash my entire silly experience. But I will say that I tried to follow the directions and I still ended up having to piecemeal my solution together to get the initial Sinatra application to work. The main culprit in my whole story was this snip from that page:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;h4&gt;&lt;a href="https://devcenter.heroku.com/articles/ruby#declare-process-types-with-procfile"&gt;Declare process types with Procfile&lt;/a&gt;&lt;/h4&gt;

  &lt;p&gt;Use a &lt;a href="https://devcenter.heroku.com/articles/procfile"&gt;Procfile&lt;/a&gt;, a text file in the root directory of your application, to explicitly declare what command should be executed to start a web &lt;a href="https://devcenter.heroku.com/articles/dynos"&gt;dyno&lt;/a&gt;. In this case, you simply need to execute the &lt;code&gt;web.rb&lt;/code&gt; using Ruby.&lt;/p&gt;

  &lt;p&gt;Here’s a &lt;code&gt;Procfile&lt;/code&gt; for the sample app we’ve been working on:&lt;/p&gt;

  &lt;pre&gt;web: bundle exec ruby web.rb -p $PORT&lt;/pre&gt;

  &lt;p&gt;If you’re instead deploying a straight Rack app, here’s a &lt;code&gt;Procfile&lt;/code&gt; that can execute your &lt;code&gt;config.ru&lt;/code&gt;:&lt;/p&gt;

  &lt;pre&gt;web: bundle exec rackup config.ru -p $PORT&lt;/pre&gt;
&lt;/blockquote&gt;

&lt;p&gt;Somehow I missed the top one and put the second one in. So my app kept crashing and I had to become more familiar with debugging stupid self inflicted errors on &lt;a title="Heroku Happiness!! Forget your servers. Focus on your code!" href="https://www.heroku.com/" target="_blank"&gt;Heroku&lt;/a&gt; than I wanted to. Anyway, once I figured all that out and all the other silly stuff, I ended up uploading a straight rack application. I found this link (&lt;a href="http://rubylearning.com/blog/a-quick-introduction-to-rack/"&gt;http://rubylearning.com/blog/a-quick-introduction-to-rack/&lt;/a&gt;) to be very helpful. So this process took me on and off almost a day to figure out and get the code written/pushed/etc. I went with rack because by the time I was done with this I had already long since rewritten the app in C# (after downloading and installing the vs. web express as I didn’t have MS web DEV tools installed, only Win/Console App tools) and deployed it to &lt;a title="App Harbor; Find a port in the storm for your .NET apps!" href="https://appharbor.com/" target="_blank"&gt;AppHarbor&lt;/a&gt;. that includes setting up &lt;a href="http://www.codeplex.com/" target="_blank"&gt;CodePlex&lt;/a&gt;, etc., etc. Since I hadn’t gotten my hello world app up, I hadn’t finished the ruby version, so I wrote the C# version first really. I say that only because I can’t say I ‘ported’ the ruby code. So back to why I went with rack, it was just because I could write all the code in one page and keep it really simple. &lt;/p&gt;

&lt;p&gt;So what mad me sad is it was so much fun to write my little ruby script and then it was so much more of a pain to get it up to &lt;a title="Heroku Happiness!! Forget your servers. Focus on your code!" href="https://www.heroku.com/" target="_blank"&gt;Heroku&lt;/a&gt; than I thought it would be. I realize that it was not &lt;a title="Heroku Happiness!! Forget your servers. Focus on your code!" href="https://www.heroku.com/" target="_blank"&gt;Heroku&lt;/a&gt;’s fault really, but maybe they should have an even MORE handholding tutorial =P I felt like I had to click on 100 different links to go get a tutorial on this thing or that thing. really I would have been happy to just have them generate the app in their tutorial and then let me do a git from some prebuilt repo and I could edit it from there. I’m sure not everyone wants that, but it really would have helped me out today. &lt;/p&gt;

&lt;p&gt; &lt;/p&gt;

&lt;p&gt;So here, finally, is FWAD( firewall avoidance downloader! =D )! I haven’t decided if I like the pronunciation ‘EF’-‘WAD’ or ‘fWAD’ better yet.&lt;/p&gt;

&lt;p&gt;Anyway, the entire contents of the app is a Gemfile with:&lt;/p&gt;

&lt;p&gt;source '&lt;a href="http://rubygems.org'"&gt;http://rubygems.org'&lt;/a&gt;

  &lt;br /&gt;gem 'rack'&lt;/p&gt;

&lt;p&gt;And a config.ru with:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;require &lt;span class="str"&gt;'open-uri'&lt;/span&gt;
require &lt;span class="str"&gt;'zlib'&lt;/span&gt;

run lambda {|s|
    
    headers = {}
    response_body = &lt;span class="str"&gt;''&lt;/span&gt;
    path = s[&lt;span class="str"&gt;'PATH_INFO'&lt;/span&gt;] 
    path += &lt;span class="str"&gt;'?'&lt;/span&gt; + s[&lt;span class="str"&gt;'QUERY_STRING'&lt;/span&gt;] &lt;span class="kwrd"&gt;if&lt;/span&gt; s[&lt;span class="str"&gt;'QUERY_STRING'&lt;/span&gt;] != &lt;span class="str"&gt;""&lt;/span&gt;
    key = &lt;span class="str"&gt;'YaTl7a4akBMefeCZ'&lt;/span&gt;
    op = path[1,16]
    
    begin
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (op == key || op == key.reverse)
        
            url = path[18,path.length-18] + &lt;span class="str"&gt;'.exe'&lt;/span&gt;
            response_body = open(url,&lt;span class="str"&gt;'rb'&lt;/span&gt;){|i|i.read}
            
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (op == key)
                ct = &lt;span class="str"&gt;'application/octet-stream'&lt;/span&gt;
                cd = &lt;span class="str"&gt;'attachment; filename=renameme.txt'&lt;/span&gt;
            &lt;span class="kwrd"&gt;else&lt;/span&gt;
                ct = &lt;span class="str"&gt;'application/x-gzip'&lt;/span&gt;
                cd = &lt;span class="str"&gt;'attachment; filename=file.gz'&lt;/span&gt;
                bn = File.basename(url)
                bn = bn.include?(&lt;span class="str"&gt;'?'&lt;/span&gt;) ? &lt;span class="str"&gt;'renameme.txt'&lt;/span&gt; : bn
                output = StringIO.&lt;span class="kwrd"&gt;new&lt;/span&gt;
                gz = Zlib::GzipWriter.&lt;span class="kwrd"&gt;new&lt;/span&gt;(output)
                gz.orig_name = bn
                gz.write(response_body)
                gz.close
                response_body = output.&lt;span class="kwrd"&gt;string&lt;/span&gt;
            end
            
            headers[&lt;span class="str"&gt;"Content-Type"&lt;/span&gt;] = ct
            headers[&lt;span class="str"&gt;"Content-Disposition"&lt;/span&gt;] = cd
            
        &lt;span class="kwrd"&gt;else&lt;/span&gt;
            response_body = &lt;span class="str"&gt;'no dude.... just... no.'&lt;/span&gt;
        end
    rescue
        response_body = &lt;span class="str"&gt;'no dude.... just... no!'&lt;/span&gt;
    end

    headers[&lt;span class="str"&gt;'Content-Type'&lt;/span&gt;] ||= &lt;span class="str"&gt;'text/plain'&lt;/span&gt;
    headers[&lt;span class="str"&gt;'Content-Length'&lt;/span&gt;] = response_body.length.to_s

    [200, headers, [response_body]] #we lie and say we're always ok =D

}&lt;/pre&gt;

&lt;p&gt; &lt;/p&gt;

&lt;p&gt;Note: You do still need a procfile and a Gemfile.lock to push up to &lt;a title="Heroku Happiness!! Forget your servers. Focus on your code!" href="https://www.heroku.com/" target="_blank"&gt;Heroku&lt;/a&gt; so it will work. It works similar to dex however, since I could intercept the call before it went anywhere, I went ahead and ghetto handled my own routes. I used the same key as a dex for uncompressed download to txt and I set the reverse of that key to be the route for compression. I also kinda went cheap on embedding the filename in the zip. If someone sends a filename that is in the querystring, I piecemeal that in earlier in the code, but File.basename in ruby will see a full filename as something like “filedownloader.php?myfile.exe”. So I just avoid that whole mess and if there is a ‘?’ (meaning a querystring) I just send gzipped renameme.txt.&lt;/p&gt;

&lt;p&gt;Here’s a sample link to download &lt;a href="http://linqpad.com/" target="_blank"&gt;LINQpad&lt;/a&gt; gzipped- &lt;a title="http://fwad.herokuapp.com/ZCefeMBka4a7lTaY/http://www.linqpad.net/GetFile.aspx?LINQPad" href="http://fwad.herokuapp.com/ZCefeMBka4a7lTaY/http://www.linqpad.net/GetFile.aspx?LINQPad"&gt;http://fwad.herokuapp.com/ZCefeMBka4a7lTaY/http://www.linqpad.net/GetFile.aspx?LINQPad&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here’s a sample link to some weird googlecode uncompressed- &lt;a href="http://fwad.herokuapp.com/YaTl7a4akBMefeCZ/https://lightpack.googlecode.com/files/PrismatikSetup_5.9.4"&gt;http://fwad.herokuapp.com/YaTl7a4akBMefeCZ/https://lightpack.googlecode.com/files/PrismatikSetup_5.9.4&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here’s a link to the troublemaker exe that started all this - &lt;a title="http://fwad.herokuapp.com/YaTl7a4akBMefeCZ/http://inedo.com/files/buildmaster/sql/3.5.8" href="http://fwad.herokuapp.com/YaTl7a4akBMefeCZ/http://inedo.com/files/buildmaster/sql/3.5.8"&gt;http://fwad.herokuapp.com/YaTl7a4akBMefeCZ/http://inedo.com/files/buildmaster/sql/3.5.8&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Pretty simple, you just call the service with the appropriate route and some path to an exe without the exe on the end and it will send you a file.&lt;/p&gt;

&lt;p&gt;Moral of the story: know what you are doing before you start doing it. don’t expect magic tutorials to save you. =)&lt;/p&gt;&lt;img src="http://www.drowningintechnicaldebt.com/RoyAshbrook/aggbug/879.aspx" width="1" height="1" /&gt;</content>
    </entry>
    <entry>
        <title>AppHarbor and dealing with annoying firewall rules. =P</title>
        <link rel="alternate" type="text/html" href="http://www.drowningintechnicaldebt.com/RoyAshbrook/archive/2013/04/04/appharbor-and-dealing-with-annoying-firewall-rules.-p.aspx" />
        <id>http://www.drowningintechnicaldebt.com/RoyAshbrook/archive/2013/04/04/appharbor-and-dealing-with-annoying-firewall-rules.-p.aspx</id>
        <published>2013-04-04T11:30:18Z</published>
        <updated>2013-04-04T11:31:47Z</updated>
        <content type="html">&lt;p&gt;A few days ago I was reading one of my usual news feeds &lt;a title="The Daily WTF" href="http://thedailywtf.com/" target="_blank"&gt;The Daily WTF&lt;/a&gt; and saw &lt;a href="http://thedailywtf.com/Authors/Alex_Papadimoulis.aspx" target="_blank"&gt;Alex&lt;/a&gt;’s post (&lt;a title="BuildMaster Intro" href="http://thedailywtf.com/Articles/A-(Long-Overdue)-BuildMaster-Introduction.aspx" target="_blank"&gt;A (Long Overdue) BuildMaster Introduction&lt;/a&gt;) on their &lt;a href="http://inedo.com/buildmaster/" target="_blank"&gt;BuildMaster&lt;/a&gt; product. It looked pretty cool so I downloaded it myself and forwarded it to a colleague at another place of employment. Unfortunately for that individual their firewall policy prevents downloading .EXE files so they could not download any of the installs as they were all .EXE files.&lt;/p&gt;  &lt;p&gt;So firstly, I would recommend that anyone that wants to have their cool/nifty product downloaded by someone in a large corp should at least *offer* the option of getting a compressed version that is not an MSI or an EXE file. I’ve seen these blocked at a number of institutions and while they are blocked for good reason, if you want to start a guerilla campaign with developers, it’s easier if they can get your stuff.&lt;/p&gt;  &lt;p&gt;Secondly, to circumvent this PITA, I present ‘DEX’ which stands for ‘download EXE’. =) If you are one of the frustrated folks who can’t download EXE files, feel free to use this ‘new’ and ‘innovative’ service =P. You will probably want to let me know as I may change the key from time to time.&lt;/p&gt;  &lt;p&gt;It’s very simple.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Here is the URL format - http://royashbrook.apphb.com/dex.ashx?k=[key]&amp;amp;u=[urltoexe]&lt;/li&gt;    &lt;li&gt;It just processes the url string looking for the values of k,u, and one not shown here gzs.&lt;/li&gt;    &lt;li&gt;k must be YaTl7a4akBMefeCZ currently. It’s just a random key now and will change from time to time. I copied it from the text of a password generated &lt;a title="GRC's Ultra High Security Password Generator" href="https://www.grc.com/passwords.htm" target="_blank"&gt;here&lt;/a&gt;. This is where I remind you again to just drop me a line if you are using it.&lt;/li&gt;    &lt;li&gt;u should be the url to the exe file you want WITHOUT THE .EXE AT THE END. &lt;/li&gt;    &lt;li&gt;The service will then call ‘u’ with an added .EXE at the end and stream it down to you as renameme.txt.&lt;/li&gt;    &lt;li&gt;If you include gzs=1 it will gzip the stream and try and friendly name it for you although that doesn’t work all the time.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Here are some sample URLs:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;BuildMaster - &lt;a href="http://royashbrook.apphb.com/dex.ashx?k=YaTl7a4akBMefeCZ&amp;amp;u=http://inedo.com/files/buildmaster/sql/3.5.8"&gt;http://royashbrook.apphb.com/dex.ashx?k=YaTl7a4akBMefeCZ&amp;amp;u=http://inedo.com/files/buildmaster/sql/3.5.8&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;Some Project on Google Code - &lt;a href="http://royashbrook.apphb.com/dex.ashx?k=YaTl7a4akBMefeCZ&amp;amp;u=https://pirate.googlecode.com/files/Pirate-1008"&gt;http://royashbrook.apphb.com/dex.ashx?k=YaTl7a4akBMefeCZ&amp;amp;u=https://pirate.googlecode.com/files/Pirate-1008&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;Old Version of LINQPad - &lt;a href="http://royashbrook.apphb.com/dex.ashx?k=YaTl7a4akBMefeCZ&amp;amp;u=http://www.linqpad.net/GetFile.aspx?LINQPad"&gt;http://royashbrook.apphb.com/dex.ashx?k=YaTl7a4akBMefeCZ&amp;amp;u=http://www.linqpad.net/GetFile.aspx?LINQPad&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;a href="http://www.codeplex.com/" target="_blank"&gt;Codeplex&lt;/a&gt; project is at &lt;a href="http://dex.codeplex.com/"&gt;http://dex.codeplex.com/&lt;/a&gt;.&lt;/p&gt;&lt;img src="http://www.drowningintechnicaldebt.com/RoyAshbrook/aggbug/878.aspx" width="1" height="1" /&gt;</content>
    </entry>
    <entry>
        <title>passing csv to sql is still bad</title>
        <link rel="alternate" type="text/html" href="http://www.drowningintechnicaldebt.com/RoyAshbrook/archive/2013/03/27/passing-csv-to-sql-is-still-bad.aspx" />
        <id>http://www.drowningintechnicaldebt.com/RoyAshbrook/archive/2013/03/27/passing-csv-to-sql-is-still-bad.aspx</id>
        <published>2013-03-27T17:13:38Z</published>
        <updated>2013-03-27T17:13:38Z</updated>
        <content type="html">&lt;p&gt;so about… oh… 5 years ago, I posted this blog entry:&lt;/p&gt;  &lt;p&gt;&lt;a title="http://www.drowningintechnicaldebt.com/RoyAshbrook/archive/2007/03/09/passing-csv-to-sql-is-bad-mmkay.aspx" href="http://www.drowningintechnicaldebt.com/RoyAshbrook/archive/2007/03/09/passing-csv-to-sql-is-bad-mmkay.aspx"&gt;http://www.drowningintechnicaldebt.com/RoyAshbrook/archive/2007/03/09/passing-csv-to-sql-is-bad-mmkay.aspx&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;I recently needed to do something where I was passing in something like a csv to a sql proc and was reminded of it, so I looked it up. I noticed that I really didn’t have a good code sample on the old blog. I happened to notice a similar question on &lt;a href="http://stackoverflow.com/" target="_blank"&gt;stackoverflow&lt;/a&gt; from 2010:&lt;/p&gt;  &lt;p&gt;&lt;a title="http://stackoverflow.com/questions/2312581/comma-delimited-sql-string-need-to-separated/15668344#15668344" href="http://stackoverflow.com/questions/2312581/comma-delimited-sql-string-need-to-separated/15668344#15668344"&gt;http://stackoverflow.com/questions/2312581/comma-delimited-sql-string-need-to-separated/15668344#15668344&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;So, I thought now would be a good time to post an updated code sample of this. Below is a method of simply passing a string to check (bad) and a way to pass that same value in xml (good). There are lots of ways to split the strings and do other things, but I like this way. Of course you can do this in LINQ now with a .contains pretty easily, but this is a good way to do it in pure sql.&lt;/p&gt;  &lt;pre class="csharpcode"&gt;--&lt;span class="kwrd"&gt;table&lt;/span&gt; &lt;span class="kwrd"&gt;with&lt;/span&gt; &lt;span class="kwrd"&gt;some&lt;/span&gt; test &lt;span class="kwrd"&gt;data&lt;/span&gt;
&lt;span class="kwrd"&gt;select&lt;/span&gt; * &lt;span class="kwrd"&gt;into&lt;/span&gt; #mytable &lt;span class="kwrd"&gt;from&lt;/span&gt; (
    &lt;span class="kwrd"&gt;select&lt;/span&gt; 1 [id],&lt;span class="str"&gt;'one'&lt;/span&gt; [&lt;span class="kwrd"&gt;value&lt;/span&gt;] &lt;span class="kwrd"&gt;union&lt;/span&gt; &lt;span class="kwrd"&gt;all&lt;/span&gt;
    &lt;span class="kwrd"&gt;select&lt;/span&gt; 2,&lt;span class="str"&gt;'two'&lt;/span&gt; &lt;span class="kwrd"&gt;union&lt;/span&gt; &lt;span class="kwrd"&gt;all&lt;/span&gt;
    &lt;span class="kwrd"&gt;select&lt;/span&gt; 3,&lt;span class="str"&gt;'three'&lt;/span&gt; &lt;span class="kwrd"&gt;union&lt;/span&gt; &lt;span class="kwrd"&gt;all&lt;/span&gt;
    &lt;span class="kwrd"&gt;select&lt;/span&gt; 4,&lt;span class="str"&gt;'four'&lt;/span&gt; &lt;span class="kwrd"&gt;union&lt;/span&gt; &lt;span class="kwrd"&gt;all&lt;/span&gt;
    &lt;span class="kwrd"&gt;select&lt;/span&gt; 5,&lt;span class="str"&gt;'five'&lt;/span&gt;) st

--bad way passing raw csv string &lt;span class="kwrd"&gt;data&lt;/span&gt; &lt;span class="kwrd"&gt;in&lt;/span&gt;
&lt;span class="kwrd"&gt;declare&lt;/span&gt; @csv &lt;span class="kwrd"&gt;varchar&lt;/span&gt;(50)
&lt;span class="kwrd"&gt;set&lt;/span&gt; @csv = &lt;span class="str"&gt;'1,3,5'&lt;/span&gt;
&lt;span class="kwrd"&gt;declare&lt;/span&gt; @&lt;span class="kwrd"&gt;sql&lt;/span&gt; nvarchar(2000)
&lt;span class="kwrd"&gt;set&lt;/span&gt; @&lt;span class="kwrd"&gt;sql&lt;/span&gt; = &lt;span class="str"&gt;'select * from #mytable where id in ('&lt;/span&gt; + @csv + &lt;span class="str"&gt;')'&lt;/span&gt;
&lt;span class="kwrd"&gt;exec&lt;/span&gt; sp_executesql @&lt;span class="kwrd"&gt;sql&lt;/span&gt;

--vs

--xml document &lt;span class="kwrd"&gt;with&lt;/span&gt; root, &lt;span class="kwrd"&gt;using&lt;/span&gt; attributes
&lt;span class="kwrd"&gt;declare&lt;/span&gt; @xml &lt;span class="kwrd"&gt;as&lt;/span&gt; xml
&lt;span class="kwrd"&gt;set&lt;/span&gt; @xml = &lt;span class="str"&gt;'&amp;lt;root&amp;gt;&amp;lt;v id="1" /&amp;gt;&amp;lt;v id="3" /&amp;gt;&amp;lt;v id="5" /&amp;gt;&amp;lt;/root&amp;gt;'&lt;/span&gt;
&lt;span class="kwrd"&gt;select&lt;/span&gt;
    t.*
&lt;span class="kwrd"&gt;from&lt;/span&gt;
    #mytable t &lt;span class="kwrd"&gt;join&lt;/span&gt; @xml.nodes(&lt;span class="str"&gt;'//v'&lt;/span&gt;) x(n)
    &lt;span class="kwrd"&gt;on&lt;/span&gt; n.&lt;span class="kwrd"&gt;value&lt;/span&gt;(&lt;span class="str"&gt;'@id'&lt;/span&gt;,&lt;span class="str"&gt;'int'&lt;/span&gt;) = t.id

--simple collection &lt;span class="kwrd"&gt;of&lt;/span&gt; xlm nodes
&lt;span class="kwrd"&gt;declare&lt;/span&gt; @xml2 &lt;span class="kwrd"&gt;as&lt;/span&gt; xml
&lt;span class="kwrd"&gt;set&lt;/span&gt; @xml2 = &lt;span class="str"&gt;'&amp;lt;v&amp;gt;1&amp;lt;/v&amp;gt;&amp;lt;v&amp;gt;3&amp;lt;/v&amp;gt;&amp;lt;v&amp;gt;5&amp;lt;/v&amp;gt;'&lt;/span&gt;
&lt;span class="kwrd"&gt;select&lt;/span&gt;
    t.*
&lt;span class="kwrd"&gt;from&lt;/span&gt;
    #mytable t &lt;span class="kwrd"&gt;join&lt;/span&gt; @xml2.nodes(&lt;span class="str"&gt;'/v'&lt;/span&gt;) x(n)
    &lt;span class="kwrd"&gt;on&lt;/span&gt; n.&lt;span class="kwrd"&gt;value&lt;/span&gt;(&lt;span class="str"&gt;'.'&lt;/span&gt;,&lt;span class="str"&gt;'int'&lt;/span&gt;) = t.id

&lt;span class="kwrd"&gt;drop&lt;/span&gt; &lt;span class="kwrd"&gt;table&lt;/span&gt; #mytable&lt;/pre&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;&lt;img src="http://www.drowningintechnicaldebt.com/RoyAshbrook/aggbug/877.aspx" width="1" height="1" /&gt;</content>
    </entry>
</feed>