How to return an nvarchar(max) in a CLR UDF?

Assuming following definition: /// <summary> /// Replaces each occurrence of sPattern in sInput with sReplace. This is done /// with the CLR: /// new RegEx(sPattern, RegexOptions.Multiline).Replace(sInput, sReplace). /// The result of the replacement is the return value. /// </summary> [SqlFunction(IsDeterministic = true)] public static SqlString FRegexReplace(string sInput, string sPattern, string sReplace) { return new Regex(sPattern, […]

How to develop t-sql in Visual Studio?

We are using Visual Studio 2013 with SSDT mainly for versioning t-sql code, so the sql is being developed on the dev server and then we use schema compare to transfer the scripts into visual studio (and check into Git). Before deployment (which we currently do with schema compare, too) we have to replace database […]

How to convert Visual Foxpro database into SQL Server database

One of my clients has a Foxpro database (.DBF file). I need to convert it into a SQL Server 2008 database. Does anyone have any idea how to do this? Kindly give me solution. Thanks in advance….

Best (easiest) way to make a SQL Server dump and import that dump in another SQL Server

I would like to achieve a database export (dump) in SQL Server from one server and import that dump in another SQL Server and not necessarily in the same schema name. For example if I have a database prepared with all the data set for implement a new DB for a new customer, that db […]

SQL Server function intermittent performance issues

We have a function in our database that searches two large tables to see if a value exists. It is a pretty large query, but it is optimized to use indexes and generally runs pretty fast. Three times over the past 2 weeks, this function decided to go haywire and run extremely slow, which causes […]

What is the advantage of using FAST_FORWARD for defining a cursor?

What is the advantage of using FAST_FORWARD for defining a cursor? Is it better for performance? why?

Sql server table usage statistics

I want to find out which tables in the database are most heavily used (I mean read/write Bytes/Table Size ratio) or IO / Table size ratio. To decide which tables to place on faster discs and which on slower ones. Any ideas? I tried make use of dm_db_index_usage_stats But how to find out how many […]

How to select a row based on its row number?

I’m working on a small project in which I’ll need to select a record from a temporary table based on the actual row number of the record. How can I select a record based on its row number?

Cannot bulk load because the file could not be opened. Operating System Error Code 3

I’m trying to set up a Stored Procedure as a SQL Server Agent Job and it’s giving me the following error, Cannot bulk load because the file “P:\file.csv” could not be opened. Operating system error code 3(failed to retrieve text for this error. Reason: 15105). [SQLSTATE 42000] (Error 4861) Funny thing is the Stored Procedure […]

How do I perform an exact string match on a non-case sensitive field?

I would like to find all the rows in a table and match on an exact case sensitive string. Unfortunately, my table has the case insensitive collation. What is the most efficient way to perform this. Eg. I would like the following to return no rows: select * from sysobject where name = ‘Sysbinobjs’ For […]

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