Does SQL Server Management Studio truncate your results?

Ever work with query results that are so long SQL Server Management Studio truncates the results?

truncated query results

sproc results are truncated

I ran into this issue recently while running some utility sprocs that generate C# code for me.  I was thinking I’d have to refactor my sprocs, but then I found this helpful setting under Query Options.

This is the Query Options dialog

Update Max.num characters per column in Query Options > Results > Text

This solved my problem and will hopefully solve yours as well.

  1. Right click the query editor
  2. Left click “Query Options…”
  3. Expand Results in the tree on the left ( in popup dialog )
  4. Click on Text under Results
  5. Set “Maximum number of characters displayed in each column” to a number large enough to see all your results.

Quick and easy, hope I remember this setting.

How to JOIN two tables using LINQ to SQL

Wanted to share this since it gave me so much trouble figuring out.  It’s a simple SQL query ported to LINQ to SQL that joins two tables to return a filtered listed of data.

Here are the tables from my schema
user, user_video, video tables

Here is a basic SQL statement I could fire to retrieve my user videos.

select  *
from    video v, user_videos uv
where   v.vid = uv.vid
and     uv.uid = 2

User 2 has two videos
Here is how you would run the same query using .net’s LINQ to SQL.

// create DB connection
var db = new DBCONN();
// run query
List<video> uvids = (
    from c in db.video
    join o in db.user_videos
    on c.vid equals o.vid
    where o.uid == 2
    select c
).ToList();

This query differs slightly from the screenshot below because I used it in a WCF Service.

Same data, different retrieval method

The variable DBCONN is my database connection that I established when mapping my DB.  If you are not familiar with how to set this up, use the Visual Studio’s “Add the ADO.NET Entity Data Model” wizard.  With your .net project open, right click your project, left click on “Add the ADO.NET Entity Data Model”.  This wizard will walk you through setting up everything you need to setup your DB model file ( edmx ), as well as setting up your database connection and saving it in web.config.

Jesse Liberty did a simple tutorial that uses this wizard in a WCF service application.

I hope this helps somebody out.