unique column in table
HI, merging table1 in table2 merge into table2 using table1 on table.col1=table2.col1 when not match then insert how to add unique column with auto increament number and not null in table like uniquenumner; Name;' 001 Test1 003 …
![](https://techprofile.blob.core.windows.net/images/c4mRkDtLdU6n6fSv2i9uBg.png?8D843C)
Training database PUBS
Dear friends, I'm looking for a description of the tables and fields of the Pubs training database. Can you help me please? Thank you very much, Anna
Microsoft SQL Server Studio - Dark Mode
Is there any official method to use Microsoft SQL Server Management Studio Studio with Dark Mode?
![](https://techprofile.blob.core.windows.net/images/XHDS-x5WFEm9V1LmsTe7Fg.png?8DBFD6)
Sporadic INSERT EXEC failed because the stored procedure altered the schema of the target table
Hi everybody, We're getting this error sporadically. The outer stored procedure has a table variable and it also has a temporary table called #Results which is used to hold results of another stored procedure, e.g. DROP TABLE IF EXISTS…
![](https://techprofile.blob.core.windows.net/images/c4mRkDtLdU6n6fSv2i9uBg.png?8D843C)
Select alternate rows basis on pattern
I have a table like below I want the result like below Please help on this. Thanks in advance.
![](https://techprofile.blob.core.windows.net/images/JiX-lf2_BgAAAAAAAAAAAA.png?8D8532)
Preventing Database Deletion in SSMS
prevent accidental database deletions within SQL Server Management Studio (SSMS). Currently, I am exploring options to enforce this restriction effectively implemented a DDL trigger Is the above DDL trigger approach appropriate for preventing…
Query to get Month , Day and Week number of current month.
Hi, Need a query to get Month , Day and Week number of current month. Sample table DateMonth NameDayWeekYear6/29/2024JunSatWK52024
How to calculate Median Value
Suppose i have table and one column has numeric value. now how could i calculate median value ? i found one code from this url https://stackoverflow.com/questions/1342898/function-to-calculate-median-in-sql-server but their approach is not…
![](https://techprofile.blob.core.windows.net/images/PAgwkj_Bw0ioCC6s8QJlQQ.png?8D9E16)
Msg 22050, Level 16, State 1, Line 0 Failed to initialize sqlcmd library with error number -2147467259.
DECLARE @RowId NVARCHAR(255) DECLARE @Query NVARCHAR(MAX) DECLARE @Header NVARCHAR(MAX) SET @RowId = '[sep=,' + CHAR(13) + CHAR(10) + 'RowId]' SET @Query = 'set nocount on; SELECT ROW_NUMBER() OVER (ORDER BY PDTMO.MONo DESC, PDTWF.CreateDate ASC) AS ' +…
Insert with Transaction Significantly Faster than Individual Inserts - SQL Server
Hello, Could you please explain this? Why insert with Transaction significantly faster than individual inserts in SQL Server?
Sql join query with total row
Hi , please help create table #temp (LedgerID INT, Amount Decimal(18,3)) insert into #temp (LedgerID,Amount) values (121,100),(121,250),(129,25),(129,200),(158,100),(158,500),(157,250),(157,100),(48625,1000) CREATE TABLE #temp_table ( cid INT, type…
SP execution time varies with different environment
Dev environment is restored with the latest Test. When a SP with same set of parameter is executed against Test as well as Dev, the execution time is differing with both the environments. In Test it takes 1.45 mins, whereas in Dev it is 3.16/3.08…
SQL : Stored Procedure variables if returning 0 or null values do not run next steps
Hi Team - If any of the 4 variables are returning 0 or NULL value do not run the next insert scripts. Could you please help how i can write a condition. TIA Create PROCEDURE [FIN].[Test] @PeriodToAllocate varchar(8) /* */ AS SET NOCOUNT ON DECLARE…
![](https://techprofile.blob.core.windows.net/images/YC3KiAudCk6A0I6NB9vOyA.png?8DA953)
convert returns conversion error but try_convert does return the correct value
Hi All, I have the following case statement in a TSQL script, which returns the correct negative decimal value, in the rows that acually have a value try_convert (decimal (18,6), max (case when [databody.daysQuality.testResults.testType] =…
left and right join
Hi, table 1 Table 2 select A.* from table1a LEFT join table2 b on a.col1=b.col1 output: which is correct but on right join it shows above results how to calculate this join and how it will react on NULL and blank
![](https://techprofile.blob.core.windows.net/images/c4mRkDtLdU6n6fSv2i9uBg.png?8D843C)
Syntax - How to use variable in LIKE clause
Trying to use a variable in the LIKE clause of a SELECT statement. Hope this is simple, but available guidance hasn't worked. As seen below, query works when a "fixed" value is used with wildcard characters, but I haven't managed to get it with…
elapsed_time value more than query execution time?
I did take query from here in order to check performance of our queries. Executed a SP which took execution time of 1 min 45 seconds. Ran the query from the link which uses the view 'sys.dm_exec_query_stats' Highlighted rows in the screenshots are…
ID's coming back as nulls are not appearing in my data set
I am trying to create a, intergrity check that bring back data after a record has been cancelled after a certain event. In my query. I am joining to a few tables and I can see all the old cancelled record. When I then cancel any new records, some IDs I…
Unexpected truncation error when inserting from UTF8 to non-UTF8 collation
I believe I am hitting a bug with moving data from a UTF8 to a non-UTF8 collations in SQL Server 2022 CU13 (running under Linux but assuming for now this issue is not related). The issue is that MSSQL appears to be determining the width of a string for…
![](https://techprofile.blob.core.windows.net/images/c4mRkDtLdU6n6fSv2i9uBg.png?8D843C)
“user_scans” of table “sys.dm_db_index_usage_stats”
I am trying to find answer to the below. What exactly the scan means for the field "user_scans" being with the table "sys.dm_db_index_usage_stats" ? Like, there are tables in our prod which aren't used for sure as the module is…