T-SQL split string

I’ve used this SQL before which may work for you:- CREATE FUNCTION dbo.splitstring ( @stringToSplit VARCHAR(MAX) ) RETURNS @returnList TABLE ([Name] [nvarchar] (500)) AS BEGIN DECLARE @name NVARCHAR(255) DECLARE @pos INT WHILE CHARINDEX(‘,’, @stringToSplit) > 0 BEGIN SELECT @pos = CHARINDEX(‘,’, @stringToSplit) SELECT @name = SUBSTRING(@stringToSplit, 1, @pos-1) INSERT INTO @returnList SELECT @name SELECT @stringToSplit … Read more

How to drop column with constraint?

First you should drop the problematic DEFAULT constraint, after that you can drop the column alter table tbloffers drop constraint [ConstraintName] go alter table tbloffers drop column checkin But the error may appear from other reasons – for example the user defined function or view with SCHEMABINDING option set for them. UPD: Completely automated dropping … Read more

How to split a comma-separated value to columns

Your purpose can be solved using following query – Select Value , Substring(FullName, 1,Charindex(‘,’, FullName)-1) as Name, Substring(FullName, Charindex(‘,’, FullName)+1, LEN(FullName)) as Surname from Table1 There is no readymade Split function in sql server, so we need to create user defined function. CREATE FUNCTION Split ( @InputString VARCHAR(8000), @Delimiter VARCHAR(50) ) RETURNS @Items TABLE ( … Read more

How can I find out what FOREIGN KEY constraint references a table in SQL Server?

Here it is: SELECT OBJECT_NAME(f.parent_object_id) TableName, COL_NAME(fc.parent_object_id,fc.parent_column_id) ColName FROM sys.foreign_keys AS f INNER JOIN sys.foreign_key_columns AS fc ON f.OBJECT_ID = fc.constraint_object_id INNER JOIN sys.tables t ON t.OBJECT_ID = fc.referenced_object_id WHERE OBJECT_NAME (f.referenced_object_id) = ‘YourTableName’ This way, you’ll get the referencing table and column name. Edited to use sys.tables instead of generic sys.objects as per comment … Read more

Why is SQL Server 2008 Management Studio Intellisense not working?

I understand this post is old but if anybody is still searching and has not found a solution to the intellisense issue even after re-installing, applying the cumulative updates, or other methods, then I hope I may be of assistance. I have Applied SQL 2008 R2 Service Pack 1 which you can download here http://www.microsoft.com/download/en/details.aspx?id=26727 … Read more

A transport-level error has occurred when receiving results from the server [closed]

The database connection is closed by the database server. The connection remains valid in the connection pool of your app; as a result, when you pickup the shared connection string and try to execute it’s not able to reach the database. If you are developing Visual Studio, simply close the temporary web server on your … Read more

Enable ‘xp_cmdshell’ SQL Server

You need to enable it. Check out the Permission section of the xp_cmdshell MSDN docs: http://msdn.microsoft.com/en-us/library/ms190693.aspx: — To allow advanced options to be changed. EXEC sp_configure ‘show advanced options’, 1 GO — To update the currently configured value for advanced options. RECONFIGURE GO — To enable the feature. EXEC sp_configure ‘xp_cmdshell’, 1 GO — To … Read more

How to find current transaction level?

Run this: SELECT CASE transaction_isolation_level WHEN 0 THEN ‘Unspecified’ WHEN 1 THEN ‘ReadUncommitted’ WHEN 2 THEN ‘ReadCommitted’ WHEN 3 THEN ‘Repeatable’ WHEN 4 THEN ‘Serializable’ WHEN 5 THEN ‘Snapshot’ END AS TRANSACTION_ISOLATION_LEVEL FROM sys.dm_exec_sessions where session_id = @@SPID learn.microsoft.com reference for the constant values.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)