SQL Server Convert integer to binary string

I was wondering if there was an easy way in SQL to convert an integer to its binary representation and then store it as a varchar. For example 5 would be converted to “101” and stored as a varchar.

TSQL Email Validation (without regex)

Ok, there are a million regexes out there for validating an email address, but how about some basic email validation that can be integrated into a TSQL query for Sql Server 2005? I don’t want to use a CLR procedure or function. Just straight TSQL. Has anybody tackled this already?

How to delete large data of table in SQL without log?

I have a large data table. There are 10 million records in this table. What is the best way for this query Delete LargeTable where readTime < dateadd(MONTH,-7,GETDATE())

SQL Server: Extract Table Meta-Data (description, fields and their data types)

I am trying to find a way to extract information about my tables in SQL Server (2008). The data I need needs to include the description of the table (filled from the Description property in the Properties Window), a list of fields of that table and their respective data types. Is there any way I […]

What is the maximum number of characters that nvarchar(MAX) will hold?

I’m new to the concept nvarchar(MAX). How many characters will it hold?

SQL GROUP BY CASE statement with aggregate function

I have a column that looks something like this: CASE WHEN col1 > col2 THEN SUM(col3*col4) ELSE 0 END AS some_product And I would like to put it in my GROUP BY clause, but this seems to cause problems because there is an aggregate function in column. Is there a way to GROUP BY a […]

How to retrieve data from a SQL Server database in C#?

I have a database table with 3 columns firstname, Lastname and age. In my C# Windows application I have 3 textboxes called textbox1… I made my connectivity to my SQL Server using this code: SqlConnection con = new SqlConnection(“Data Source = .; Initial Catalog = domain; Integrated Security = True”); con.Open(); SqlCommand cmd = new […]

'datetime2' error when using entity framework in VS 2010 .net 4.0

Getting this error: System.Data.SqlClient.SqlException : The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value. My entity objects all line up to the DB objects. I found only a single reference to this error via Google: Google result After reading this, I remember that we did add 2 […]

For Nvarchar(Max) I am only getting 4000 characters in TSQL?

This is for SS 2005. Why I am i only getting 4000 characters and not 8000? It truncates the string @SQL1 at 4000. ALTER PROCEDURE sp_AlloctionReport( @where NVARCHAR(1000), @alldate NVARCHAR(200), @alldateprevweek NVARCHAR(200)) AS DECLARE @SQL1 NVARCHAR(Max) SET @SQL1 = ‘SELECT DISTINCT VenueInfo.VenueID, VenueInfo.VenueName, VenuePanels.PanelID, VenueInfo.CompanyName, VenuePanels.ProductCode, VenuePanels.MF, VenueInfo.Address1, VenueInfo.Address2, ” As AllocationDate, ” As AbbreviationCode, […]

How do you specify a different port number in SQL Management Studio?

I am trying to connect to a Microsoft SQL 2005 server which is not on port 1433. How do I indicate a different port number when connecting to the server using SQL Management Studio?

MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.