Quantcast
Channel: SQLServerCentral » SQL Server 2012 » SQL Server 2012 - T-SQL » Latest topics

Convert string MMDDYYYY to a date

First I will say I've found a couple different SQL solutions for this, I'm asking if there is a better way or what would be the most efficient way of doing this.  I'm also making an assumption that...

View Article


Query Question

I have a table that contains multiple fields:Diagnosis1Diagnosis2Diagnosis3Diagnosis4Diagnosis5Diagnosis6Diagnosis7Diagnosis8Diagnosis9each field only contain codes, the descriptions are in another...

View Article


Question on Grouping -Working number of days

Hi All,I am trying to work out the number of days for each (CODE) from the Code (REQUEST DATE) till next Code appear and update the ( No.Days) .it was working fine using LAG/LEAD function but...

View Article

Window Function

Hello,Good evening.I am trying to find the latest checking lot no based on each receiving which matches with available with inventory level. Please refer to the below picture for your kind perusal.For...

View Article

Split Date into From and ToDate

Hi friends,I would like to split the date into from and to date range based up on Quantity change and also need to ignore the record if Date is missing in between them. Any suggestions would be really app

View Article


Expand multi-join with another table

Hi all,I'm have a SQL agent job (running in live business situation) and it's doing the following:-read data from source DB (and some additional lookup) and keep it in a view  (see code)This has all...

View Article

Combine multiple stored procedures to create one report using cursor.

What I'm trying to achieve should look like this and my stored procedure should accept a single argument – the name of a College, it will need to find all Colleges that match the name (including...

View Article

Transfer a text file from one server to another server

Is there any way to transfer a text file from one server to another server using powershellscript.Please help .

View Article


XML XQuery shred into fully encapsulated individual rows

I cant seem to work out a query that returns fully encapsulated shredded xml.This will get me very close, but missing the parent node, and anything at the second level (L1ID,L1Name) [code...

View Article


How to round a value in a varchar column ?

Dear Forum,I have a strange requirement to round a value in a varchar column in MS SQL*Server 2012. I know it is bad practice to hold numerics in a varchar.i.e. the column is a varchar but holds a...

View Article

How to determine what percent of a varchar column is a valid numeric?

I have a data profiling type of question :I'm interesting in a query to determine what percent of a varchar column is a valid numeric?sql*server 2012.i.e. the varchar column may hold a value like 123.4...

View Article

Various ODBC File Data Type Images must be written in the proper format on to...

Hello Folks.In a table are stored over 1 million ODBC documents (doc, pdf, excel ). I want to write all this documents on to disk in the correct format. The format is given by an attribute in the...

View Article

VARBINARY not storing the original value

View Article


Select Column Value based on date

HI ,I'm looking for some help figuring out how to go about Selecting Column Value based on  todays date.I have a columns 1 through 31 and Id like to select that value for today. eg: today is the...

View Article

Table Join with Grouping problem

Morning,I'm looking for some help on my query, it really a grouping problem.I've joined 2 unsimilar tables (different db's)  to get a value not available in the 1st table. The 2nd table has different...

View Article


Overlapping Date Ranges

Hi there,I have looked in many forums and have been unable to find what I am looking for to get the results I need.Basically I am looking to see if a physician has 2 or more overlapping enrollment...

View Article

SQL QUERY: Request For Part Overflow

I have events on my database.Every event has datetime to be started and datetime to be ended.In every event appears request for part/s. Inventory of this parts just 2 units (not appears in the example...

View Article


Save the actual execution plan of a SQL statement in a script

I have a script that runs in SSIS from an "Execute SQL Task". One statement that is taking about 1 hour in my test environment is taking about 10 hours in production, on similar sized data. I suspect...

View Article

Parse string based on a list of values

Rather that use a bunch of replace functions, is there a better way to parse these values, CH,HC,MA,NH,OA,OTH,PSY,SNF, out of my data?[code language="sql"]

View Article

Image may be NSFW.
Clik here to view.

Subset rows with opening and closing balance

Hello All,I trying to get result as mentioned below (excel format for illustration purpose only). 

View Article

query regarding compare-object output

Hello ,Can anybody help me with below :compare-object (get-content file1.txt) (get-content file.txt)| where { $_.SideIndicator -eq '<='}InputObject          SideIndicator<

View Article


Job Schedule KO / SQL Server 2012R2

Hello everyone.Let me first explain what the job does. Basically it executes a T-SQL query (customer data) puts the data in an excel file then send it by email.This job works perfectly when I run it...

View Article


I‌ wanted to run a stored proc over 500 databases in production.

Hello Room,I'm not hundred percent sure on how to program in T-SQL.I wanted to run a stored proc over  500 databases in production.and, the stored procedures will detect the  expensive stored proc on...

View Article

Issue updating columns for existing rows

Hi there,so I have this table I've added additional columns to. For existing rows I want to update the columns with new values. PK_Time is a Primary Key int and represents the date as YYYYMMDD and SSMS...

View Article

Union with co-related subquery

I am trying to take MAX(date) from the result set of three different tables using a UNION operator. so here is the query I used. But I am getting the error like "The column prefix 'e' doesnot match...

View Article


trimming SSNs

I have thousands of social security numbers I need to trim to leave only the last 4 digits... it is in a varchar field as xxx-xx-xxxx sometimes, but others are in xxxxxxxxx format and some scraps are...

View Article

How to return a value if an INNER JOIN isn't satisfied?

Hi,I have Historical T-SQL query as below:SELECT<

View Article

Joining a result set to a base table

I have a weird one that is hard to explain.So I am looking for any Providers that are not listed as a Primary.  So I did a select PROVID from PROVSPECIALTY  (#primary) table which gives me about 73000...

View Article

Convert function and omitting the optional length parameter

I'm keen to use the convert function to convert many (100s) of nvarchar columns to varchar columns via creation of a view and an SSIS package.Each column has different length or many of them do.If I...

View Article



Alternative to sp_OACreate, sp_OAMethod, and sp_OADestroy call a url for...

I have created the following sproc for calling a URL to return XML. However, we dont have access to run sp_OAMethod. The call is below. My question is there an alternative way to call a URL to return XML?

View Article

Convert xml column data from x and shred the elements into a tabular structure.

I am looking to have the xml column converted into a table. Basically shred the xml into columns. I am not familiar with XML and tried a tad bit of stuff but couldn't make any progress. Any help would...

View Article

Split strings by space into individual rows

Hi,String operations are one of my weakest areas in SQL. My requirement is to split strings separated by spaces with different lengths. Products column contains product information for each activity...

View Article

get percentage of sale quantity based on items from same group verses the -12...

So in the example I divide the quantity of each item by the quantity of 230-12. I would like to do this in the QUERY . The results will be a long list of different PartClasses, Partgroup's and PartID's...

View Article


t-sql 2012 sum of several fields

In the t-sql 2012 orig sql listed below, I am trying to determine how to tell if at least 2 or more of the following values are not null:The fields that I am looking for to be not null are the...

View Article

Running out of TempDB when using MERGE Query

Hello,We have a .NET application that executes a stored procedure in SQL that runs a Merge Query for UPDATES, INSERTS, DELETES.  I know the MERGE runs a single batch.  The source table that is being...

View Article

Excluding values using NOT IN not working

I posted last week or so about joining results to an existing table and I tried all the responses but nothing worked. I wanted to make a test mockup of data so it might explain it better

View Article


need help with writing query to retrieve info stored in multiple columns

I need help with creating query to retrieve info stored in multiple columns.  Below you can find sample table/info with current output and the required/preferred output.Tablecreate table...

View Article


deleting duplicates, even though different key values

Is there a way of deleting duplicates, even though different key values? e.g.:123 Mary Kay124 Mary Kay125 Bob Incus126 Bob Incusget rid of only one of the duplicates like leave 123, delete 124

View Article

Recursive CTE Duplication

Hi all,I am working on a system that has Business units and a Parent\Child relationship.I am trying to write a CTE that will show me all of the descendants for any given BU.  I feel i am nearly there.

View Article

Split sting by hypens

Hi Guys,I have one task to derived column values by splitting the string by hypensbelow is the DDL,[code language="sql"]CREATE TABLE #TABLE(COL VARCHAR (100) )INSER

View Article