Skip to content
Advertisement

Tag: sql-server

Hamming weight/population count in T-SQL

I’m looking for a fast way to calculate the hamming weight/population count/”the number of 1 bits” of a BINARY(1024) field. MySQL has a BIT_COUNT function that does something like that. I couldn’t find a similar function in T-SQL? Or would you suggest storing the binary data in a field of another type? If you don’t know what I’m talking about,

Generate class from database table

How can I generate a class from a SQL Server table object? I’m not talking about using some ORM. I just need to create the entities (simple class). Something like: Given some table like: Answer Set @TableName to the name of your table.

Caching SQL queries

If I look in my profiler for SQL-server, it comes up with a lot of duplicate queries such as: A lot of these queries are not needed to display real time data, that is, if someone inserted a new record that was matched in that query it wouldn’t matter if it didn’t display for up to an hour after insertion.

SQL query for today’s date minus two months

I want to select all the records in a table where their date of entry is older then 2 months. Any idea how I can do that? I haven’t tried anything yet but I am on this point: Answer If you are using SQL Server try this: Based on your update it would be:

Advertisement