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

Date column conversion - yyyy-mm-dd to yyyy-mm-01...please help

Hi,   I have a date column values like 2013-08-25,2013-08-01,2013-09-01 and 2013-09-005 Now I want to make them in such a way that if the datapart value is more than 1, then it should be 1... so, the...

View Article


Need solution for ex-30 in sql-ex.ru

 Here  is the questionUnder the assumption that the income (inc) and expenses (out) of the money at each outlet (point) are registered any number of times a day, get a result set with fields: outlet,...

View Article


how to select last two words from a string...

I need a sql statement to get the last two words from a string....Example:  Table A      1. what is your name     2. What's your birth placeThe query should return 1.your name2. Birth place..help...

View Article

Cursor much faster when loop. What's wrong ?

Hello All! I tried to modify script (not my) and this script contains the cursor inside:SELECT TOP(100) * INTO #tmpTable FROM MyTable WHERE MyDate<@ThisDateDECLARE My_Cursor CURSOR FOR SELECT ID,...

View Article

Finding duplicate records from two tables

I have  table T1 with more than 1000 Records and there are few dulpicates in this table T1 SELECT segment, LandUseGroup, StateAbbreviation,Unit  FROM  T1 WHERE EXISTS ( SELECT  Sc_id, bMP_ID,segment,...

View Article


MSG 107

USE UMDW GO DECLARE @TERM AS char(4) SET @TERM = '1133' SELECT DISTINCT a.EMPLID,a.GRADE_POINTS,a.UNT_TAKEN_GPA INTO #COHORT_LIST FROM PS_DWSA_ST_CAR_TRM a INNER JOIN playground.dbo.AY_GPA_COHORT_1213...

View Article

best way to change the value in a table?? (sorry i am a sql noob) :)

Sorry to post this, but it should be some easy points for someone more familiar with T-SQL... as i have inherited this role and previously only had to query data from a database not edit it. (select...

View Article

Duplicate Across Multiple Tables

I need help in planning the best course of action to find duplicates from multiple tables.      DECLARE @Table1 TABLE (ID_T1 int, Col1 varchar(10), C2 varchar(10), C3 varchar(10), C4 varchar(10), Col5...

View Article


I (didn't) find a BUG with the T-SQL Right () function :-þ

I have discovered a bug that exists in both SQL 2008 SP2 and SQL 2012 SP1 T-SQL.SELECT '000' + cast(  cast('010' as int)-1 as char(3) ) AS NewSeq  -- Correctly Results in 0009SELECT RIGHT('000' + cast(...

View Article


Select Rows Based on Entire 'Subset' Matching Condition

Hi All, Using SQL Server 2008 R2.  Below is DDL and Sample Data: CREATE TABLE [dbo].[Sample](    [SampleID] [varchar](50) NOT NULL,    [Description] [varchar](50) NULL GO CREATE TABLE...

View Article

Continue script after error (sp_refreshsqlmodule)

Hi,I am trying to update object dependency metadata in the db (sql server 2008R2), using sp_refreshsqlmodule stored procedure. I created cursor that goes through all stored procedures and runs...

View Article

Another variation on row concatenation

Hi,Suppose I have a table like this:IF OBJECT_ID('dbo.Soils', 'U') IS NOT NULL DROP TABLE dbo.Soils; CREATE TABLE Soils( CHKEY varchar (5) NULL, LAYER1 int NULL, A1 decimal (4, 1) NULL, B1 decimal (4,...

View Article

find matching data in columns

Id     Seg       Value          St    Unit 124009 HIGHMANMD percent 124015 HIGHMANMD percent 124021 HIGHMANMD percent 124021 HIGHMANMD Acres 124023 HIGHMANMD percent 124043 HIGHMANMD percent 142001...

View Article


Getting data from a week and also that same week in previous months.

I have an issue with some data im trying to get here is my scenariowe'll use the week of august 18-24th for my examplethe user will want the data from this week, but also will want data from the...

View Article

need time part from datetime column with AM/PM format in SQL 2008

Hi,I want only time part from a datetime column in SQL 2008.I also want to achieve the below,1. I want the format as "hour:minute:second"2. followed by a space and then AM/PM.Example,07:23:45...

View Article


Renaming databases - code and gotchas

Re: Renaming databases - code and gotchasWe are implmenting a rolling database history. We are going to keep 13 months of productiondb snapshots. At the end of each month db13 is renamed to db0, 12 to...

View Article

lab reservation query

I've following tableLabType         StartDate                                              EndDate2                    2013-09-03 09:30:00.000                     2013-09-03 10:30:00.0002...

View Article


FULL JOIN does not work as expected

Hi,I have a very long and complex query - so I cannot post it here in full.It works fine, until I add the last join statement (highlighted in yellow)-----------------------------------FROM dbo.OITW T0...

View Article

Query runs very slowly only in particular database while its ok in other...

Dear All,I have this strange issue with one of the queries in one particular database. First to put some light on the background I will describe in short the configuration:1. Microsoft SQL Server 2008...

View Article

Delete performance - Nested subqueries vs Join

Hi, I'm trying to understand the performance difference between two queries.  I've had to change the table names as I can't post schema details online! I stumbled across a stored procedure which seemed...

View Article
Browsing all 23857 articles
Browse latest View live


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