Quantcast
Channel: Transact-SQL forum
Browsing all 23857 articles
Browse latest View live

Image may be NSFW.
Clik here to view.

Same SQL queries are giving me diffrent results please Help...

View Article


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 Article


How 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 Article

Merging two rows into single row

Hi All,Scenario 1                               Scenario 2s1500s1500s1400s1400s2200s2200s2300s2700Resultneed s2500S2700  Feb'13Mar'13April'13May'13S1500400  S2200 300 

View Article

Concatenation 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 Article


Create 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 Article

Query 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 Article

Sqlserver 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 Article


how 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 Article


OS 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 Article

Image may be NSFW.
Clik here to view.

Help 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 Article

Reducing index size

Hi All.How can I reduce the index size on a table? is rebuilding helps?thnx,G

View Article

SQL- 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 Article


Number 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 Article

I 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 Article


How 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 Article

Image may be NSFW.
Clik here to view.

SET 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 Article


Column 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 Article

Tsql

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 Article

Image may be NSFW.
Clik here to view.

inheritance 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
Browsing all 23857 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>