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

Match part of column value with other column

Hi All,I have a table  Customer which has values like belowCustomerNameSam Billisto(sbillisto) Som Hanks (shanks)jennifer shin(jshin)I have another table CustomerKey which has following columns and...

View Article


Merge statement syntax question

In a merge statement, when source and target not matched you insert, but when source and target matched and current_flag='Y'. You update the end_date and current_flag='N' but where are we updating the...

View Article


Min and max

hiselect id,min(actual) Min_Actual, max(actual) max_actual, count(id)  from main group by id in min and max, i need to exclude actual = 0,  If use WHERE Acutal <> 0, my count(ID) will be wrong,...

View Article

single upsert statement

Hi All,I want to update/insert data in a table based on the value of a primary columnEx: Create Table Table1 (AccountID INT,LastName Varchar(10),FirstName Varchar(10),Email Varchar(50),Address1...

View Article

delete year(getdate() -2) and month as 12

my source table column is ReportingPeriod Nvarchar(6) delete query has to be for datas before 2 years. this is not working delete from table where ReportingPeriod < year(getdate() -2) and month as...

View Article


Rounding - Always Round Up

Hi All, Is there a way in T-SQL using the round command to always round up regadless of the value.  For example:ROUND(normal_hours * pay_rate * 52, - 3) AS Expr3 normal_hours = 36pay rate = 23.64weeks...

View Article

Join statement not working

I have 2 Tables:Users ------------ UserName FirstName LastNameTickets --------------------- TicketID TicketTitle TicketDescription UserNameI am trying to tget the FirstName from the Users Table based...

View Article

I'm being stupid, again. Sum & Count, together

Hi-I thought that this should be easy and I was able to do this...nope.i need to sum a value for each distinct count.  Having read a few post, i think i need an over() function.select distinct...

View Article


Odd problem/bug with view in SQL Server 2012

I am using SQL Server 2012, do not have the exact build # handy though.I created a view:create view myView as  a.*, b.storeName, b.storeLocation from  Sales a inner join  Stores b on a.StoresID =...

View Article


substring

Hi everyone,I have a data like belownumber057740500041010408721960200201900077853I need to take out last 2 digits of right side if the 2 digits are 00,01,02,03,04,05,06,07,08,09 only and take out all...

View Article

calling a table from another server

Hi everyone,I am trying to retrieve the data from a table which is on the different server. how do I do that? I am doing in the following way ., but I am getting an error like "Invalid object name...

View Article

Left Outer Join on same table

Hi All,We are with sql server 2012. I am asked to take over the maintenance of some stored procs. I am not that familiar with complex stored procedures. It was written by one of the team members. I see...

View Article

Select first field from column in group value

Hello, I need to return the first row of data grouped by the first field (Visit ID) in multi-column table:VisitID       AdmitDate            Unit       Room          OrderCode001041      2014-08-01...

View Article


t-sql query help

Hi i have table having data like this

View Article

SQL Query CASE statement using two fields

Hi, I have two fields. One is called rescategory1, the other is called rescategory2.I'm not sure if its a CASE statement I need or some sort of WHERE clause but I want to create a query that does the...

View Article


Trim up to a certain character

 hi everyone, i hope someone can help me with this. i have a string that I need to trim up to a pipe character ("|"). the problem is, the length of the characters before this pipe character varies...

View Article

Issue with Like operator

Hello Everyone,I have values of column "Job_Name" in the below way.sderg_AS_ASDFSDFS_DF__D_FG__Dsdfsdf I have a query to print all the characters that occur before first "_" i.e, "sderg" in this...

View Article


Diffrence of last 2 rows

Hi i have a table which includes meter reading of different meters. When i give the meter id i need to take the last 2 meter reading values . My table structure and datas areCREATE TABLE MeterReading (...

View Article

How can get TOP 10 percent rows against each value of a column in Table?

i have below example. I have to select top 50 percent data rows for each value of col1. I am using SQL Server 2008.Col1        Col2A             1A             3A             5A             100B...

View Article

Text Date in sort order of date

Hi All;Below is my expression in SQL (CONVERT(CHAR(4), e.createdon, 100) + CONVERT(CHAR(4), e.createdon, 120) as createdonits gives output Oct 2013I need to sort this expression in date orderIs this...

View Article
Browsing all 12890 articles
Browse latest View live


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