LessThanDot Site Logo

LessThanDot

A decade of helpful technical content

This is an archive of the posts published to LessThanDot from 2008 to 2018, over a decade of useful content. While we're no longer adding new content, we still receive a lot of visitors and wanted to make sure the content didn't disappear forever.

A couple of ways of getting the top 2 distinct values from a set in SQL Server

In this blog post I will show you a couple of ways of getting the top 2 values from a set in SQL Server. The dense_rank queries will not work if you have SQL server 2000 but the other ones should. Let’s say you have a table that has this data 100 100 100 99 99 95 95 90 You want to get the 2 highest amounts in that table the values 100 and 99, how would you do this?

Read More...

Vulnerability in Microsoft Video ActiveX control could allow remote code execution

This is a bad one if you are running Windows XP or Windows Server 2003 with Internet Explorer. If you are running Windows Vista, Windows 7 or Windows Server 2008 then you are not affected The bad part about this is that all it takes for you is to visit a bad site. If you are using Chrome (like me), FireFox or Safari then you are not affected by this. Microsoft really should redesign IE from scratch and get rid of all that ActiveX baggage/nonsense, it is not worth it, it only causes troubles.

Read More...

SQL Server Decode/Encode unicode data

Not all systems can correctly accommodate Unicode data. Therefore, it’s not uncommon to receive data that is encoded in such a way that it can be stored in an ASCII format. Of course, SQL Server can store Unicode data easily if you use the nvarchar data type. Converting to and from Unicode data can be time consuming. When you receive data that is Unicode encoded, I suggest you decode it and store it in an nvarchar column.

Read More...

How to copy data/append data into files from within T-SQL

Sometimes you want to quickly copy some data into a text file or you want append some data to a text file but you don’t feel like opening BIDS or the DTS designer. Here is a way to accomplish what you want from within a query window To copy data into a new file use BCP (Bulk Copy Program). To append to a file use OPENROWSET Here is some sample code.

Read More...

Automatically create a SQL Server table in a new database.

I’ve seen this question numerous times in the forums I like to frequent. The idea is, when you create a new database, you may want that database to have several tables, some of which are automatically populated with data (thinking about relatively static lookup tables here). The process mentioned here may not be useful for everyone, but it is certainly something to consider. There is a system database named Model. This database is used when you create a new user database.

Read More...

Trust

Recently, I had a conversation with a friend and former co-worker. He’s essentially been running a one-man shop since I left there but the company had recently hired a new developer who claimed to be very experienced in the technologies to which the office is trying to migrate (notably .NET). My friend had been tasked with bringing the new employee up-to-speed and working with the current projects. However, there have apparently been some concerns that the new employee may not have the abilities he claimed in his interview (because it is a small shop, there was no formal technical interview) and that the new employee may not have the necessary soft skills to fit in with his co-workers.

Read More...

Reading from a HD that was formatted with ext3 from Windows Vista

Yesterday, my nas died on me, actually it didn’t, I just couldn’t connect to it any more and this thing didn’t have a USB port only ethernet. So I decided to get the disk out and mount it in my desktop. Since it was Sata that was easy. But I hit a little snag and that is that it was formatted in ext3 and windows does not read ext3 So I googled and found Linux reader 1.

Read More...

The use of descriptive variable names is forbidden

Still legacy application vbnet For x = 1 To y q(x, y + 1) = q(x, y + 1) + p(I, J) * ay(I) For z = 1 To y q(z, x) = q(z, x) + p(I, z) * p(I, x) Next z Next x I immediately refactored the I and J to be lowercase.

Read More...

Dynamic column names and fields in SSRS (Custom Matrix)

I had no choice but to do work with creating dynamic column headings and dynamically determine what field in my dataset should go where in a report today. Since this is the second time I’ve gone through this exercise and knowing the lack of information out there on really how to do it, I thought it deserves a blog entry. So here is the basis of the requirements. You have a query that uses PIVOT but thrown into the mix is the need for dynamic columns in the PIVOT.

Read More...

How To Script Out The Whole Database In SQL Server 2005 and SQL Server 2008

There seems to be a little bit of confusion on how to script out the database. The correct answer is of course: just run all the scripts you have in source control 🙂 So for those who do not use/have source control I will show you how to do it Logically you would think that this would be the way: Right click on the database –> Script Database As –> CREATE To and then pick your choice.

Read More...