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

Locating MAX of multiple date columns

I have a table with five date columns, I'm using a COALESCE CASE WHEN (example below) to produce an alias with the value of the most recent of the five date columns.  That part works fine but what I'm...

View Article


Pivot Table

I have a pivot table in my select statement, it works fine, however, I need to pivot the data again?So after I FIRST Pivot the Data I get a list of values in From a  Name column, now I want to take...

View Article


ORDER BY CASE GIVING WRONG RESULTS

SELECT FirstWord + substring(Rest, 1, charindex('~', Rest+'~') - 1) AS INVOICE, FirstWord + substring(Rest, 1, charindex('~', Rest+'~') - 1) AS INVOICESTRING,x.CUSTOMER,...

View Article

Format specific character format in Query

I have a character field for telephone #. In the query, I want to have the field in the format "(999) 999-9999". I have tried different formats in the CONVERT statement and other formatting options and...

View Article

SQL Job Fails Because of Invalid Object Name

Why would a SQL Job in SQL Server 2008 R2 complain about an object not being valid when the job is not “instructed” to access (or use) that particular object?My SQL Server hosts a database called...

View Article


TSQL Query help

abc

View Article

Conversion failed when converting the varchar value to data type int.

Hi,I am building a View with an integer column by filtering data from Master table and below is the sample script. And Select Query on the View with WHERE condition is throwing the following...

View Article

function copy to new database without create statement

One of our developer has created 5 functions. Whenever new database is created these functions should be created in it without running create statements for these functions every time after create...

View Article


Query

The inner query is returning 27 records, but when I join it with another table it returns 216 recordsselect SegInfoID from PNRSegmentInfo PNRSI inner join (select...

View Article


Ranking in SQL

I have group of riders that log miles ridden on the website. Miles are saved and summed in a mileagelog table. Currently they are ordered by total miles by the year. New requirement is to have an...

View Article

Search Server instead of Database

Is there anyway to search an entire SERVER, instead of individual databases?Because I have to change the database name and then run the script to find any stored procs where a key word exists.SELECT...

View Article

Crosstab two joined tables multiplies the data in each column ....

below is code that crosstabs monthy sales numbers and totals for each month.  So what I need to do is add a column that totals last years sales (table will be called [2013]) and add a column called...

View Article

How to strip out non-numeric and append to new column for same row

I have tons of records hat look like this:462 E08R E07 E09 E06 360 E04 E11 E02RSome are numeric, but most are not.I want to take all alphanumeric records and convert add a column next to the record,...

View Article


How can I convert Float numbers which are represented as 'E-05' to full...

I have over 6,000 records which all have 'E-05' in the field.It should actually be full precision, such as:  0.000046793055472781How can I convert all of these?  There are around 600,000 records in the...

View Article

Parent ID of Table

Hi all, DECLARE @BaseLevel1 TABLE ( ID INT, Level1Category Nvarchar(20) )DECLARE @BaseLevel2 TABLE ( ID INT, BaseLevel1 INT, Level2Category Nvarchar(20) )INSERT INTO @BaseLevel1 VALUES (1, 'Alpha')...

View Article


cursor or case statement?

PartyTypeID FunctionType 4 Display Name 5 Organization Name 6 Band Name 7 Alias 8 Venue Name 9 Legal Name 10 Abbreviated NameI have table like above in Relational database form, I am working on store...

View Article

Help send query in HTML

So I have the below sql job that is send me the information but in a non readable format. I would like to make this an HTML email. Can you please help me.I have try to reproduce...

View Article


Image may be NSFW.
Clik here to view.

Calculate number of days based on System Date and a date column!

Hi everyone,I have a query to run a report where the results has a column named “Due Date” which holds a date value based on the project submission date.Now, I need to add 4 columns named, “45 Days...

View Article

Nested Split WITHOUT Cross APPLY

I have been wrestling with this for days and need an assist.I have to split a text field based on different Delimitters AND I need to do it without CROSS Apply because the database I am working in has...

View Article

Image may be NSFW.
Clik here to view.

convert one to many relation to one to one without using subquery .

Gurus,I am wondering if there can be a more efficient way of converting the "one to many relation output" to "One to one" Without using subquery. TableStructurescreate table orders (OrderID int,...

View Article
Browsing all 23857 articles
Browse latest View live


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