sql-server

Usage of SP_OACreate, SP_OAMethod etc.. is a security risk ?

I am told that usage of SP_OACreate , SP_OAMethod in SQL Server 2000 is of a security risk. I am using Strong Name in the assembly and is stored in GAC on the SQL Server Machine. What are the security implications/compromise ? ...

From varchar(36) to UNIQUEIDENTIFIER

I am trying to cast an AuctionId that is a UNIQUEIDENTIFIER to an varchar(36) and then back to an UNIQUEIDENTIFIER. Please help me. CAST((SUBSTRING(CAST([AuctionId] as VARCHAR(36)), 0, 35) + '1') AS UNIQUEIDENTIFIER) But I keep getting this error: Msg 8169, Level 16, State 2, Line 647 Conversion failed when converting from a c...

Database task to delete table records periodcally in sql server 2008

I want to add a database task that runs on a 6 hours interval. The task is to delete some records that matches certain condition. What is the best way to achieve this in Sql Server 2008 ? I know I can do this on the app side but I want it on sql server side. ...

Load SQL query result data into cache in advance

I have the following situation: .net 3.5 WinForm client app accessing SQL Server 2008 Some queries returning relatively big amount of data are used quite often by a form Users are using local SQL Express and restarting their machines at least daily Other users are working remotely over slow network connections The problem is that aft...

T-SQL Syntax Issue Else if style logic

Hi guys, two questions today, I'm a busy bee and luckily I have an awesome community at my disposal! My issue here is this: I have a field i need to update based on existing field data. If Gender = F then foo = 1 If Gender = M then foo = 2 If Gender = Male then foo = 2 If Gender = Female then foo = 1 If Gender is not above then fo...

Can I use @table variable in SQL Server Report Builder?

Using SQL Server 2008 Reporting services: I'm trying to write a report that displays some correlated data so I thought to use a @table variable like so DECLARE @Results TABLE (Number int ,Name nvarchar(250) ,Total1 money ,Total2 money ) insert ...

INSERT 2000 records into SQL Database all at a time from C# .NET code

We need to INSERT 2000 records into SQL DB from C# .Net code. For this is there any way to INSERT all 2000 records at a time instead of executing the INSERT query for each record. Also how would be the performance impact of doing this? Thanks & Regards Padma ...

Combine First, Middle Initial, Last name and Suffix in T-SQL (No extra spaces)

I'm trying not to reinvent the wheel here...I have these four fields [tbl_Contacts].[FirstName], [tbl_Contacts].[MiddleInitial], [tbl_Contacts].[LastName], [tbl_Contacts].[Suffix] And I want to create a FullName field in a view, but I can't have extra spaces if fields are blank...So I can't do FirstName + ' ' + MiddleInitial + ' ' + L...

SQL Server - Schema/Code Analysis Rules - What would your rules include?

We're using Visual Studio Database Edition (DBPro) to manage our schema. This is a great tool that, among the many things it can do, can analyse our schema and T-SQL code based on rules (much like what FxCop does with C# code), and flag certain things as warnings and errors. Some example rules might be that every table must have a prima...

Getting maximum value of float in SQL programatically

Is there an method for programatically (in T-SQL) retrieving the maximum (and minimum) value of a datatype? That it would act like float.MaxValue in C#. I would like to use it in some selection when the parameter does not equal any actual values in the database, so I would use something like declare @min float declare @max float --fill...

How to reduce time for taken by stored Procedure for inserting a single record?

We wrote a stored procedure for selecting a single record from DB at a time. Using the same stored procedure to read 2000 records it takes 4 seconds. Is there any way to optimize it? (like single stored procedure for 2000 records) Thanks & Regards Padma ...

Should I be regularly shrinking my DB or at least my log file?

My question is, should I be running one or both of the shrink command regularly, DBCC SHRINKDATABASE OR DBCC SHRINKFILE ============================= background Sql Server: Database is 200 gigs, logs are 150 gigs. running this command SELECT name ,size/128.0 - CAST(FILEPROPERTY(name, 'SpaceUsed') AS int) / 128.0 AS Availabl...

SQL Server - Convert date field to UTC

I have recently updated my system to record date/times as UTC as previously they were storing as local time. I now need to convert all the local stored date/times to UTC. I was wondering if there is any built in function, similar to .NET's ConvertTime method? I am trying to avoid having to write a utility app to do this for me. Any su...

SQL select statement filtering

Ok, so I'm trying to select an amount of rows from a column that holds the value 3, but only if there are no rows containing 10 or 4, if there are rows containing 10 or 4 I only want to show those. What would be a good syntax to do that? So far I've been attempting a CASE WHEN statement, but I can't seem to figure it out. Any help woul...

Is is possible to run multiple instances of SQL Server on the same machine

Is is possible to run multiple instances (installations) of SQL Server databases on the same machine (assuming the machine is not virtualized) ...

Clustering SQL Server

Can we combine multiple installations of Microsoft SQL Server 2005 or 2008 to act as a single database cluster? ...

T-sql COLLATE and Varchar(max)

Hi When u use Varchar(max), it is 8000 chars for a variable, and around 2^32 for a column, what is COLLATE and how it affects that? Thanks ...

Will SQL Server Partitioning increase performance without changing filegroups

Scenario I have a 10 million row table. I partition it into 10 partitions, which results in 1 million rows per partition but I do not do anything else (like move the partitions to different file groups or spindles) Will I see a performance increase? Is this in effect like creating 10 smaller tables? If I have queries that perform key...

SQL Server 2005 - Find minimum unused value within a range

I have a situation similar to the following question: Insert Data Into SQL Table Where my scenario differs is that I have a non-auto-incrementing primary key field that can have a range between 1000 and 1999. We only have about a hundred values in it thus far, but the maximum value has already been taken (1999), and there are gaps in t...

Why Banks or Financial Companies prefer Oracle than other RDBMS for their "Core" systems?

I'd like to know why most Banks or Financial companies prefer Oracle than other RDBMS for their core systems (the absolutely minimum features that a Bank must support). I found a few answers that didn't satisfy me. For example: Oracle has more features. But features for what? Can't you implement that in application level if you were not ...