Executing a stored procedure within a stored procedure
T-SQL is not asynchronous, so you really have no choice but to wait until SP2 ends. Luckily, that’s what you want. CREATE PROCEDURE SP1 AS EXEC SP2 PRINT ‘Done’
T-SQL is not asynchronous, so you really have no choice but to wait until SP2 ends. Luckily, that’s what you want. CREATE PROCEDURE SP1 AS EXEC SP2 PRINT ‘Done’
nvarchar(max) is really a different data type from nvarchar(integer-length). It’s characteristics are more like the deprecated text data type. If nvarchar(max) value becomes too large, like text, it will be stored outside the row (a row is constrained to 8000 bytes maximum) and a pointer to it is stored in the row itself. You cannot … Read more
The command you’re looking for is: alter table tblName drop column columnName where tblName is the name of the table and columnName is the name of the column, but there’s a few things you may need to do first. If there are any foreign key references to the column, you’ll need to get rid of … Read more
You have few options to use a network file as a backup source Map network drive/path, hosting file, under SAME user as MS-SQL Server. Use xp_cmdshell extended stored procedure to map network drive from inside of MS SQL (such way, command shell will have the same privilegies as the user account running SSMS) — allow … Read more
You can get the difference between the two dates to whatever resolution you want (in your example, minutes): DATEDIFF(minute, @start_date, @end_date) From there it’s a simple matter of dividing minutes into hours and hours into days and modding the remainder.
static void InsertSettings(IEnumerable<Entry> settings) { using (SqlConnection oConnection = new SqlConnection(“Data Source=(local);Initial Catalog=Wip;Integrated Security=True”)) { oConnection.Open(); using (SqlTransaction oTransaction = oConnection.BeginTransaction()) { using (SqlCommand oCommand = oConnection.CreateCommand()) { oCommand.Transaction = oTransaction; oCommand.CommandType = CommandType.Text; oCommand.CommandText = “INSERT INTO [Setting] ([Key], [Value]) VALUES (@key, @value);”; oCommand.Parameters.Add(new SqlParameter(“@key”, SqlDbType.NChar)); oCommand.Parameters.Add(new SqlParameter(“@value”, SqlDbType.NChar)); try { foreach (var oSetting … Read more
You can use a function with COALESCE. CREATE FUNCTION [dbo].[GetAliasesById] ( @userID int ) RETURNS varchar(max) AS BEGIN declare @output varchar(max) select @output = COALESCE(@output + ‘, ‘, ”) + alias from UserAliases where userid = @userID return @output END GO SELECT UserID, dbo.GetAliasesByID(UserID) FROM UserAliases GROUP BY UserID GO
The only sane way to update a table of 120M records is with a SELECT statement that populates a second table. You have to take care when doing this. Instructions below. Simple Case For a table w/out a clustered index, during a time w/out concurrent DML: SELECT *, new_col = 1 INTO clone.BaseTable FROM dbo.BaseTable … Read more
You can insert into a varbinary(max) field using T-SQL within SQL Server Management Studio and in particular using the OPENROWSET commmand. For example: INSERT Production.ProductPhoto ( ThumbnailPhoto, ThumbnailPhotoFilePath, LargePhoto, LargePhotoFilePath ) SELECT ThumbnailPhoto.*, null, null, N’tricycle_pink.gif’ FROM OPENROWSET (BULK ‘c:\images\tricycle.jpg’, SINGLE_BLOB) ThumbnailPhoto Take a look at the following documentation for a good example/walkthrough Working With … Read more
I just had the same error, and it was down to a corrupted index. Re-indexing the table fixed the problem.