sql-server

Function to find the Exact match in MS SQL Server

What is the way to find the exactly matching substring in the given string in MS SQL server. For example, in this string '0000020354', I want to find '20354'. Of course it has to be exact match. I tried to use CHARINDEX(@providerId, external_prv_id) > -1, but the probem with CHARINDEX is that it gives me the index as soon as it finds the...

Creating column with user defined constraint

I want to limit my varchar columns to have only ascii characters within a specified range, say 0-9 or A-F (for hex characters) What would my constraint look like? ...

sql server 2008 newsequentialid() problem

I'm having newsequentialid() learning problems in sql server management studio. Create a table with a uniqueidentifier column 'UniqueID', and set the default to newsequentialid(). Step 1. saving the design: 'Table_1' table - Error validating the default for column 'UniqueID'. Save it anyway. Step 2. view the sql: CREATE TABLE [dbo]....

How to select all tables with a particular name in database

How do I select all the tables name with a particular name in the database? ...

sp_MSforeachdb MS SQL error

This is for MS SQL 2005: Anyone know why the first succeeds, then creating two of the same statement in succession fails? All the statements are exactly the same. Changing the double quote to two single quotes has the same effect. sp_MSforeachdb @command1 = 'if (left("?", 2) = "p_") begin; print "?"; end;'; produces p_Na...

Sql Server Column with Auto-Generated Data

I have a customer table, and my requirement is to add a new varchar column that automatically obtains a random unique value each time a new customer is created. I thought of writing an SP that randomizes a string, then check and re-generate if the string already exists. But to integrate the SP into the customer record creation process ...

Updating/Saving to a SQL Database using C#?

I can't find how to do this on google anywhere. How do you save to a SQL DB using just C# code? Is it possible? The save method that comes default when you create a DB using the wizard dosen't actually save the DB: this.Validate(); this.studentsBindingSource.EndEdit(); this.studentsTableAdapter.Update(this.studentsDataSet.FirstClass); ...

Read .NET configuration from database

The .NET 2.0 and up configuration system is quite powerful and extensible - as long as you don't want to change the fact it all comes from XML files in the filesystem. In my requirement, I cannot change files since my app runs in a managed environment outside my reach - but I could change the SQL Server database. So I am looking at sto...

Easy way to retrive timestamp from SQL Server db

I have a timestamp column (updated) in my Microsoft Sql Server Database and wish to retrieve the value as a DateTime object using SqlConnection and SqlCommand. What is the easiest way to do this? ...

How do I emulate the SSIS package progress screens SQL server uses?

When I use a wizard in SQL Server 2005 to export data, it creates and executes an SSIS package. While doing this, it has a progress display, with tasks as rows in a grid, marked with a cross or tick, depending on success, and with failure, an error message link, for more detail on the failure. Does SQL Server, SSMS, or SSIS, use a stan...

Error when installing sql server 2000 on vmware (Windows XP)

The installer crashes with instruction to check c:\windows\sqlstp.log for more information, here's what the log contains: Connecting to Server ... driver={sql server};server=JJOHN-vm;UID=sa;PWD=;database=master [Microsoft][ODBC SQL Server Driver][Shared Memory]General network error. Check your network documentation. [Microsoft][ODBC ...

Fetch Tags and Tag count using HQL on SQL Server 2008

I'm implementing tagging on a particular entity, using NHibernate on SQL Server 2008. The structure I have now is, simplifying, like this: public class Entity { public Guid Id { get; set; } } public class Tag { public Guid Id { get; set; } public string Name { get; set; } } public class TagAssoc { public Tag LinkedTag ...

Question(s) on implementing check constraints with SQL CLR integration.

I'm implementing 'check' constraints that simply call a CLR function for each constrained column. Each CLR function is one or two lines of code that attempts to construct an instance of the user-defined C# data class associated with that column. For example, a "Score" class has a constructor which throws a meaningful error message when...

Insert Update trigger how to determine if insert or update

I need to write an Insert, Update Trigger on table A which will delete all rows from table B whose one column (say Desc) has values like the value inserted/updated in the table A's column (say Col1). How would I go around writing it so that I can handle both Update and Insert cases. How would I determine if the trigger is executed for an...

Visual Studio 2008 express not recognizing my Sql Server 2008 express

I recently installed in order: Sql Server 2008 Express Visual Web Developer Express 2008 When I right click on app_data and try to add a db it returns: Connections to SQL Server files (*.mdf) require SQL Server Express 2005 to function properly. Please verify the installation of the component or download from the URL: http://go.micro...

result set

hi all, I m having a stored procedure which returns two result sets based on the success or failure. SP sucess result set: name, id ,error,desc SP failure result sret: error,desc I m using the following query to get the result of the stored procedure .It returns 0 for success and -1 for failure. declare @ret int DECLARE @tmp TABL...

Does SQL accounts lower security for MS SQL Server 2008

I have Microsoft SQL Server 2008 which we host some databases on. We currently use Windows Integration for authentication. We are starting to need the support of authenticating scripts from ASP.NET and other applications. These applications need to use "script credentials" as they run without a user logged in. We are not really wanting ...

Querying data from multiple clustered tables as one unified

Hello, I've recently started work on a project which involves creating a web-based reporting interface for a fairly old software responsible for managing some access control hardware like electronic door locks for example. I have chosen CakePHP for the task and all it involves is querying the database for the log records and displaying ...

TSQL make EXECUTE statement synchronous

I have two TSQL EXEC statements EXECUTE (N'MyDynamicallyGeneratedStoredProcedure') -- return 0 on success SELECT @errCode = @@ERROR ; IF (@errCode = 0) BEGIN EXEC 'A Sql Statement using ##temptable created from first', @returnValue END How do I make the two EXEC's synchronous? ; Right now the second EXEC does not wait for the first...

SQL Server Indexes

What's the Need for going for Non-clustered index even though table has clustered index? ...