Filter by Dates in SQL

If your dates column does not contain time information, you could get away with: WHERE dates BETWEEN ‘20121211’ and ‘20121213’ However, given your dates column is actually datetime, you want this WHERE dates >= ‘20121211’ AND dates < ‘20121214’ — i.e. 00:00 of the next day Another option for SQL Server 2008 onwards that retains … Read more

Cannot bulk load. Operating system error code 5 (Access is denied.)

This error appears when you are using SQL Server Authentication and SQL Server is not allowed to access the bulk load folder. So giving SQL server access to the folder will solve the issue. Here is how to: Go to the folder right click ->properties->Security tab->Edit->Add(on the new window) ->Advanced -> Find Now. Under the … Read more

Use SQL to filter the results of a stored procedure

There are no good ways to do that. It is a limitation of stored procedures. Your options are: Switch the procedure to a User Defined Function. All over world, today, people are making stored procedures that should be functions. It’s an education issue. You situation is a good example why. If your procedure were instead … Read more

Create SQL identity as primary key?

Simple change to syntax is all that is needed: create table ImagenesUsuario ( idImagen int not null identity(1,1) primary key ) By explicitly using the “constraint” keyword, you can give the primary key constraint a particular name rather than depending on SQL Server to auto-assign a name: create table ImagenesUsuario ( idImagen int not null … Read more