add a new column to a table with conditions
hi friends i want to add a column to a table with conditions below : 1- it has a default value=0 2- this column can get null value 3- no constraint should be created is it possible ?thanks
View ArticleHow can I force SQL Server to use a Parallelism and Merge Join operation vs....
I have a stored proc that's been running great for months and now suddenly is chosing a really crummy plan everytime even though when I run the query independently it runs instantly as it's using...
View ArticleMerging two rows into single row
Hi All,Scenario 1 Scenario 2s1500s1500s1400s1400s2200s2200s2300s2700Resultneed s2500S2700 Feb'13Mar'13April'13May'13S1500400 S2200 300
View ArticleConcatenation in where clause
I have 2 tables and each table has say 1 column with thousands of rows.create table #t1 (id varchar (2) ) create table #t2 (id varchar (2) ) insert into #t1 values('01') insert into #t1 values('2')...
View ArticleCreate a single SQL Login on many Instances
Looking to accomplish creating a single SQL login, using T-SQL, on many SQL instances that we support. This will save us from connecting to each instance manually and creating it one at a time....
View ArticleQuery needed
I have these two tables. Can somebody help with a query, to get the record from @transact which has min (createddate). I have millions of records in both the tables.declare @main table (ID int)...
View ArticleSqlserver 2012 varbinary concatenation does not work as expected
I'm seeing an strange behaviour when performining varbinary concatenation as per the following test case: Is there a bug or do I need to use another function? declare @l_header varbinary(32) declare...
View Articlehow to dynamically add leading zeros in sql query
how to dynamically add leading zeros in the below sql query. selectreplace(convert(CHAR(12),CAST(65.90ASDecimal(12,2))),'.','')65.90 is money data type columnI am getting the output like 6590,but i...
View ArticleOS cmd from within SQLCMD
I have a batch file that contains a list of SQLCMD commands, as in...SQLCMD -S server1,1433 -E -i "C:\testscript.txt" -o "C:\testscript_server1.out" :quitSQLCMD -S server2,1433 -E -i...
View ArticleHelp with complex CTE expression
Hi all,I was recently (and very kindly) helped by Jesus under the following thread Common Table Expression Help.Being a complete newbie to CTE's, I was at a loss on how to achieve my goal and whilst I...
View ArticleReducing index size
Hi All.How can I reduce the index size on a table? is rebuilding helps?thnx,G
View ArticleSQL- find overlapping prescriptions
I have a bunch of patient prescriptions, each having a certain start date and an end date. I would like to find the instances where a patient has been taking more than one drug (at the same time) in...
View ArticleNumber of Weeks
Hi Guys,Just created an script and get the week number of posteddatetime.upon comparing to my excel data the derived result is not the same.what is the difference? please advise. thanks.declare...
View ArticleI TRUNCATE Table by accident how can I restore my lost data
I TRUNCATE Table by accident how can I restore my lost dataWithout Transaction so i can't use ROLLBACK TRAN This is my code : TRUNCATE TABLE dbo.NUM;Mohamed Ahmed Database Administrator & Developer
View ArticleHow to turn related records into hierarchical recordset
Hello,I have two tables of data and the data is related. I however need it to be heirarchical for binding to a tree control and in this data set it is probable that child records will have more than...
View ArticleSET ANSI_PADDING setting
Hi everybody,I am wondering if this is wrong setting on the database level (this is what we have in our database, we also had compatibility level 100 which I just changed to 110): I am wondering if...
View ArticleColumn totals using PIVOT in SQL Server 2008 R2
Hi, How to calculate column totals using PIVOT in SQL Server 2008 R2. I would like to get column totals for each employee. Can this be done in T-SQL?USE AdventureWorks2008R2 GO SELECT VendorID, [250]...
View ArticleTsql
want to select only Int values from this column out of millions records some have Char values in front of records and some donthere is what i am looking for ColumnRequiredGLP0671929 ------->0671929...
View Articleinheritance from multiple tables into shared table
I'm attempting to store attributes common to 2 entities into 1 table (Table C) as per below diagram. The problem is that I can't maintain Referential Integrity. The Table C common attributes are...
View Article