Concatnate Values For Different Rows

May 10, 2007

Hi ,



I have a situation where i need to concatnate values from different rows and store it a one string.



sample



dealid date



1 1/5/2007

1 2/4/2009

2 5/5/2004

2 8/5/2006

2 4/8/2006





so for one particular deal how many ever dates there are , i need to concatnate them all separated by a comma(,) and return and one string.



Is ther any way i could do it, Any suggestions appreaciated



Thanks

Ashish



View 4 Replies


ADVERTISEMENT

Compare Values In Consecutive Rows And Print Rows Based On Some Conditions

May 8, 2008

I have the following variables VehicleID, TransactDate, TransactTime, OdometerReading, TransactCity, TransactState.

VehicleID is the unique vehicle ID, OdometerReading is the Odometer Reading, and the others are information related to the transaction time and location of the fuel card (similar to a credit card).

The records will be first grouped and sorted by VehicleID, TransactDate, TransactTime and OdometerReading. Then all records where the Vehicle ID and TransactDate is same for consecutive rows, AND TransactCity or TransactState are different for consecutive rows should be printed.

I also would like to add two derived variables.

1. Miles will be a derived variable that is the difference between consecutive odometer readings for the same Vehicle ID.

2. TimeDiff will be the second derived variable that will categorize the time difference for a particular vehicle on the same day.

My report should look like:

VehID TrDt TrTime TimeDiff Odometer Miles TrCity TrState
1296 1/30/2008 08:22:42 0:00:00 18301 000 Omaha NE
1296 1/30/2008 15:22:46 7:00:04 18560 259 KEARNEY NE

Can someone please help me here?

Thanks,
Romakanta

View 1 Replies View Related

Help, Selecting Rows Based On Values In Other Rows...

Mar 25, 2002

I'm stuck. I have a table that I want to pull some info from that I don''t know how to.

There are two colomuns, one is the call_id column which is not unique and the other is the call_status column which again is not unique. The call_status column can have several values, they are ('1 NEW','3 3RD RESPONDED','7 3RD RESOLVED','6 PENDING','3 SEC RESPONDED','7 SEC RESOLVED').

i.e example, this is the existing data.

Call_id Call_Status
555555 3 3RD RESPONDED
235252 7 SEC RESOLVED
555555 7 3RD RESOLVED
325252 6 PENDING
555555 6 PENDING
325235 3 SEC RESPONDED
555555 1 NEW

This is the data I want...

Call_id Call_Status
555555 3 3RD RESPONDED
555555 6 PENDING
555555 7 3RD RESOLVED

The call_id could be any number, I only want the 6 PENDING rows where there are other rows for that call_id which have either 3 3RD RESPONDED or 7 3RD RESOLVED. If someone knows how it would be a great help.

Cheers,

Chris

View 1 Replies View Related

Transact SQL :: Converting From Multiple Rows With Single Values To Single Rows With Multiple Values

May 10, 2015

Here is some data that will explain what I want to do:

Input Data:
Part ColorCode
A100 123
A100 456
A100 789
B100 456
C100 123
C100 456

Output Data:
Part ColorCode
A100 123;456;789
B100 456
C100 123;456

View 4 Replies View Related

Compressing Multiple Rows With Null Values To One Row With Out Null Values After A Pivot Transform

Jan 25, 2008

I have a pivot transform that pivots a batch type. After the pivot, each batch type has its own row with null values for the other batch types that were pivoted. I want to group two fields and max() the remaining batch types so that the multiple rows are displayed on one row. I tried using the aggregate transform, but since the batch type field is a string, the max() function fails in the package. Is there another transform or can I use the aggragate transform another way so that the max() will work on a string?

-- Ryan

View 7 Replies View Related

Transact SQL :: Selecting Rows As Column Name And Other Column Values As Rows

Jun 25, 2015

I have questions and answers from one table, I need to select questions as column names and answers column values as the results for the questions column.

View 28 Replies View Related

Spilting Values In Rows.

Jun 9, 2008

Hi guys,
I have a table like this.

Declare @tbl as table(Invoiceid int,Dc varchar(100))

Insert into @tbl
Select 1,'101,102,104'union all
Select 2,'105,106,107' union all
Select 3,'110,111,112,113,114' union all
Select 4 ,'115'

I want to split the values in the column Dc.The output should be

Invoiceid Dc
1--------- 101
1--------- 102
1--------- 104
2--------- 105
2--------- 106
2--------- 107
... and so on.
Thanks for any help.

View 3 Replies View Related

How Compare Values Of 2 Different Rows In Same Tbl

Nov 17, 2005

Hi

i have this variable called order1 in the table called datetable and i want to display out the duplicate orders in sql. how do i do that? do i need to use group by ?

thanks in advance.! any help?

well i actually get the answers by doin this...
select order1 from datetable group by order1 having count(*) > 1

however now i want to compare the values date1 in the first duplicate orders to the second duplicate order...like compare aaaa of the first row and aaaa of the second row ...how to do that? i need to compare the date1 in minutes..i only wan duplicate orders with minutes difference less than 30mins
eg

id Order1 date1
1 aaaaa 20051001 12:45
2 aaaaa 20051001 12:10
3 bbbbb 20031002 15:05
4 bbbbb 20031002 15:50

View 9 Replies View Related

How To Compare Values In Different Rows?

Jul 30, 2007

Hi

I€™ve a table like this (in SQL Server 2000).


v1 v2
2 8
7 10
11 15
13 17

v1 value of a row must be grater than v2 value of previous row, other wise I need to display that row, in above example, I need to display 2nd & 4th rows.

please advise

Thanks

View 9 Replies View Related

Column Values To Rows?

Feb 1, 2008



Good morning all,

I have a table from which I need to select every nine values in one column and insert them into another table as a row with nine different columns. For example, I need:

WERT
1A08
2A08
3A08
56999
25555
25666
12444
55699
55698

To become:

SN1 SN2 SN3 GRN1 GRN2 GRN3 GRN4 GRN5 GRN6
1A08 2A08 3A08 56999 25555 25666 12444 55699 55698

And so on and so forth for the every nine values in the column from the first table. Can somebody please help me with the correct T-SQL query to accomplish this please?

I may also need to do the same thing for other tables where I may have fifteen or so values to be extracted into a different table as rows.

Thanks in advance,

Paul

View 8 Replies View Related

Adding Values Of Rows In Ms Sql 2000

Jun 3, 2006

I am building a website in asp.net 1.1 with vb.net 2003 which will have the standings of the teams in our baseball league.  Below is the database table I have created.
 
ID(int)  home_team (nvarchar)  away_team(nvarchar)  win_teampf(nvarchar) lose_teampf(nvarchar)
1    Elmwood    Murdock    7   22    Louisville     Manley       4   33    Manley        Elmwood    9  8
ID is the primary key.  What I am attempting to do is add each instance of Elmwood from the win column to output the total number of wins from Elmwood and do the same for Elmwood in the losing team to output the total number of losses. The result will look something like this:
Elmwood: 1 Win  1 Loss. .500
Thanks for your reply.
 

View 5 Replies View Related

Comparing Column Values Among 2 Or More Rows

Jun 29, 2012

I've been working with T-SQL in a MSSQL Server Management Studio (2005) for about a week now. I've been trying to convert some horribly written VB code from a MS Access DB over to SQL so it can be automated on a SQL backend.

Most of the learning process and coding has gone surprisingly well. The problem is with comparing some data to determine which one needs to be flagged.

Three tables to note in bold, with notable fields in italics below them:

EmployeeData
HRID (identity)

ResourceAllocation
ID (identity)
[Last Name] (linked to HRID)
Project
[Resource Start Date]
[Resource End Date]
[Percent Utilization]

tblHCvalues
RAID (linked to ResourceAllocation.ID)
a monthyear and quarteryear for every month and quarter from 2012-2014. IE january12, february12, 1q12, 2q13, etc...

And yes, there are probably a thousand ways to optimize that tblHCvalues, but I'll ask about that later. Just work with the structure I have

Here's how it works: Each employee's data and unique HRID is in the EmployeeData tableAn employee can be on one or multiple projects at any timeThose projects are stored per project in the ResourceAllocation table with a link to the Employee's HRID, and all the other information listed aboveEven though an employee might be on two projects, they can only count for headcount on one project.

We use rules that compare the percent of work being done on a project, and the start and end dates of the employee (resource) on that project to determine which project should be counted for Headcount. The code uses a cursor to go through each HRID, and then pull up all the ResourceAllocation records associated with it.Run the rules to determine which ResourceAllocation record counts toward headcountA stored procedure then runs that fills out the tblHCvalues in the way we want for the project we want

All of it works, except for the rules that compare the things, so that's what I want to focus on in this thread. How do I write these rules:

Here are the rules, and they should work for any number of multiple resource allocations for one employee:

Choose the ResourceAllocation with the greatest [Percent Utilization]If the top ResourceAllocations have equal [Percent Utilization], choose the ResourceAllocation with the earliest [Resource Start Date]If the [Percent Utilization] and the [Resource Start Date] are equal, choose the latest [Resource End Date]If all three fields are equal, choose the first ResourceAllocation (aka, screw it and pick one at random)

I'm sure I could use a bunch of IF statements to compare it all, but even that is complicated to think about. There has to be an easier way, right?

View 6 Replies View Related

Compare Values In Consecutive Rows

May 8, 2008

I have the following variables VehicleID, TransactDate, TransactTime, OdometerReading, TransactCity, TransactState.

VehicleID is the unique vehicle ID, OdometerReading is the Odometer Reading, and the others are information related to the transaction time and location of the fuel card (similar to a credit card).

The records will be first grouped and sorted by VehicleID, TransactDate, TransactTime and OdometerReading. Then all records where the Vehicle ID and TransactDate is same for consecutive rows, AND TransactCity or TransactState are different for consecutive rows should be printed.

I also would like to add two derived variables.

1. Miles will be a derived variable that is the difference between consecutive odometer readings for the same Vehicle ID.

2. TimeDiff will be the second derived variable that will categorize the time difference for a particular vehicle on the same day.

My report should look like:

VehID TrDt TrTime TimeDiff Odometer Miles TrCity TrState
1296 1/30/2008 08:22:42 0:00:00 18301 000 Omaha NE
1296 1/30/2008 15:22:46 7:00:04 18560 259 KEARNEY NE

Can someone please help me here?

Thanks,
Romakanta

View 2 Replies View Related

Rows Which Are Associated With Values Greater Than Specific Value

Jun 5, 2014

I am trying to select all the data which are not associated with values older than a specific value.. For example I have:

paola -- 2
paola -- 3
paola -- 10

jessica -- 3
jessica -- 12

james -- 3
james -- 2
james -- 5

I want to query only those names, that are associated with numbers greater than 3. So, for this example, the result would be only Jessica. the others should be discarded.

View 4 Replies View Related

List Of Rows With Same Column Values

Nov 3, 2014

select pr.birthdate, pr.operationdate from patientrecord pr
Total no.of rows = 24420

select distinct pr.birthdate, pr.operationdate from patientrecord pr
Total no.of rows = 23528

It seems there are some rows with same birthdate and operationdate.

I want to get the list of rows(with all columns) that has got same birthdate and operationdate

View 1 Replies View Related

Get Rows With Duplicate Values In Certain Columns

Jul 23, 2005

Hi there,I would like to know how to get rows with duplicate values in certaincolumns. Let's say I have a table called "Songs" with the followingcolumns:artistalbumtitlegenretrackNow I would like to show the duplicate songs to the user. I considersongs that have the same artist and the same title to be the same song.Note: All columns do not have to be the same.How would I accomplish that with SQL in SQL Server?Thanks to everyone reading this. I hope somebody has an answer. I'vealready searched the whole newsgroups, but couldn't find the solution.

View 2 Replies View Related

Scripting Table With Rows Values

Jul 20, 2006

HiIs there any way to script a table (with EM or Management studio) alongwith data contained in the table (rows values)?J

View 1 Replies View Related

Checking Obligated Values In Different Rows

Jul 20, 2005

Hi there!I have a problem I can't get rid of... I hope anyone can help me with it!For a room-booking application I need to select available rooms for a givenperiod. First I do the availability check which is no problem, than I needto find out if there is a tariff available for every night of the givenperiod. If not, I will not show the room as 'available' in the systembecause I can't make a tariff calculation.All tariffs are entered in a table which can hold different night-tariffsfor different periods. The table looks like this:========CREATE TABLE [dbo].[TARIEVEN] ([TARIEF_ID] [numeric](18, 0) IDENTITY (1, 1) NOT NULL ,[FK_OBJECT_ID] [numeric](18, 0) NOT NULL ,[STARTDATUM] [datetime] NULL ,[EINDDATUM] [datetime] NULL ,[TARIEF_PRIJS] [decimal](10, 2) NULL ,) ON [PRIMARY]GOFK_OBJECT_ID is the Room IDSTARTDATUM is the startdate of a tariff periodEINDDATUM is the enddate of a tariff periodTARIEF_PRIJS is the tariff per night in the tariff period========What I do at the moment is:--------SELECT fk_object_id FROM TARIEVENwhere ('15-oct-2004' BETWEEN STARTDATUM AND EINDDATUM)AND ('16-oct-2004' BETWEEN STARTDATUM AND EINDDATUM)AND ('17-oct-2004' BETWEEN STARTDATUM AND EINDDATUM)--------This will work if all nights are in the same tariff period, but it will notproduce the right results if the tariffs are in different periods because nosingle row contains a startdate and enddate in between which all dates are.I can't use an OR statement because I absolutely need a tariff per night.So, what my question is in short:How can I for example select OBJECT 1 from the following table consideringthat I want to return all rooms which have a tariff available for a periodfrom 15th of october to 17th of october?-----------------FK_OBJECT_ID STARTDATUM EINDDATUM TARIEF_PRIJSFK_OBJECT_ID STARTDATE ENDDATE TARIFF1 10-oct-2004 16-oct-20041001 17-oct-2004 18-oct-2004125In words: object 1 costs 100 per night in the period from 10 to 16 octoberand 125 in the period from 17 to 18 october------------------I hope anyone can help me. Thanks a lot in advance!!Robert

View 8 Replies View Related

Subtract Values From Different Rows Within Query

Nov 20, 2007

I have a query that uses rollup to get totals and top 101 to restrict the rows to top 100 rows plus the total column. The total column shows total for all rows not just the top 100 which is exactly what i need. The only thing I need now is a row that shows total for all rows that have been excluded, or the total row - total of the top 100.

Here's the query: (Biggest factor i have to keep in mind is query speed.)






Code Block

WITH CTE_name AS (
SELECT TOP 101 b.name,
SUM(ISNULL(CAST(b.launched AS BIGINT),0)) AS quantityPrepared,
SUM(ISNULL(CAST(b.bounced AS BIGINT),0)) AS bounced,
SUM(ISNULL(CAST(b.delivered AS BIGINT),0)) AS delivered
FROM dimension tt
INNER HASH JOIN batch b ON (b.batch_id = tt.batch_id)
WHERE tt.datelaunched >= '11/19/2007'
AND tt.datelaunched < '11/20/2007'
AND tt.id = 1
GROUP BY b.name WITH ROLLUP
ORDER BY SUM(ISNULL(CAST(b.launched AS BIGINT),0)) DESC
)

SELECT
name,
quantityPrepared
bounced,
delivered
FROM CTE_name
ORDER BY 2

View 1 Replies View Related

Query To Get Rows Which Match With All Given Values

Sep 10, 2007

Hi all,

I would like have your help about a query.
In fact, I have a query to retrieve the rows for specific ID.
Like that:

SELECT *
FROM TblUser u
WHERE EXISTS

(

SELECT *

FROM TblScore s

WHERE s.FKIDUser = PKIDUser

)

With this query, I retrieve all users for which ones there are some scores.
Now, I need to get only users with specific score.
In the table TblScore, there is a column ScoreValue.
This column contains a value between 1 and 15

I would like to retrieve the users having score equal to 2,4 and 6
I could add a where clause like that: "and scorevalue in (2,4,6)"
But I want only users having these and only these scores, not less, not more.

So if an user has the following scores: 2,4,6,8, I don't want to retrieve it
If an user has the following scores: 2;4, I don't want to retrieve it.
If an user has the following scores: 2,4,6, I want it.

Someboy would have an idea at my problem ?

Thanks in advance
Jerome

View 7 Replies View Related

Analysis :: How To Suppress Rows With 0 Values

Jul 2, 2015

The cube going into browser or Excel, shows the following.

Measure  Measure Calculated  TotalRevenue(measure)  TotalCost(measure)  GrossMargin(calculated)  Gross Margin%(calculated)                   
    $#,##0;($#,##0)         $#,##0;($#,##0)   "$#,##0;($#,##0)"              "#,##0.0 %;(#,##0.0 %)"

The excel gives me..

A   $552,198                      ($437,190)                     $115,008                                              20.8%
B             $0                                  $0                                $0                                        

How can I suppress/hide the row with $0 values and NULL.  So the user does not need to filter, in Excel.

View 4 Replies View Related

Merge Two Rows Only If TagWidgetIDs Same But Tag Values Different?

May 15, 2015

I have this stored procedure which generates the following output.

The query which generates the output from the stored procedure is as follows:

SELECT tat.[agent-id],
tat.[agent-guid],
tat.[agent-name] AS [AgentName],
tw.TagWidgetID,
tw.TagWidgetName,
t.TagID,
core.fnInitialCapitalization(t.DisplayName) AS TagName,

[Code] ....

How can I join the output rows only if the TagWidegetIds are same but the TagValues, TagIndex and ValueIndex columns are different?

View 3 Replies View Related

How Do I Insert Values Into CE From A DataGridView Row/rows?

Mar 19, 2007

 

Hi all...  can someone tell me why this does not work and how to make it work????

 SELECT     SQLkey, CreateDateTime, Alias, PropDNumb, PropDRevNumb, PropDItem, PropDMfg, PropDCat, PropDList, PropDCost, PropDGMDollar, PropDGM,
                      PropDSellPrice, PropDXSellPrice, PropDItemTotal, PropDShipQty, PropDStatus, create_timestamp, update_timestamp, update_originator_id,
                      create_date
FROM         ProposalDetail 
INSERT INTO temp
(
SQLKey, CreateDateTime, Alias, PropDNumb, PropDRevNumb, PropDItem, PropDMfg, PropDCat, PropDList,
PropDCost, PropDGMDollar, PropDGM, PropDSellPrice, PropDXSellPrice, PropDItemTotal, PropDShipQty, PropDStatus,
create_timestamp, update_timestamp,update_originator_id, create_date
)
VALUES
(
'1', '3/20/2007 8:13:10 AM', 'SomeUser', 'b1', '4', '0761046', 'APP', 'Miscellaneous Options',
'54.000', '27.00', '27.00', '50.00', '54.00', '54.00', '54.00', '1', 'Active', '3/20/2007 8:13:10 AM', '3/20/2007 8:13:10 AM', '0',
 '3/20/2007 8:13:10 AM'
)
WHERE     (PropDNumb = 'b1') AND (PropDRevNumb = '1')

 

Thanks a ton!

View 1 Replies View Related

Calculating Change Of Values Between Rows

Aug 23, 2007

Hello forum.


I have three columns in my table with the following datatypes:

Date - DateTime
Height - Decimal
Change_From_last_Height - Decimal

I am using "SQL Server 2005 Express Edition". I'm fairly new to SQL and would greatly appreciate any help or advice I can get.

The "date" column increases by an extra day in every new row and I then enter the new height of the plant. What I want to know is how I can get SQL server express to automatically enter the difference in height between the current row's height and that of the previous row.

Is it possible to automate the entry in the Change_From_Last_Height column in SQL?

Put another way, I know how to find the difference between two values in the same row but different columns, but how do I calculate the difference between values in adjacent Rows (ie. Rows next to each other)?


Thank you.

View 3 Replies View Related

Looping Through A Table And Fetching Values From Rows

Mar 10, 2008

 I have a table (temp_Order) wherein I use to insert a temporary order... after inserting the temporary order, when the buyer submits the order,I want to loop through the table and fetch the orders made by the buyer and insert those products on another table (Order)...how can I achieve this? im currently using sqlDataSource... 

View 2 Replies View Related

Tranform Columns To Rows With Multiple Values

Sep 30, 2006

I have the following result set:

Code:


NameCode1Value1Code2Value2
A1020020250
B20300NULLNULL
CNULLNULLNULLNULL


I want to transform the columns into rows like this:

Code:


NameCodeValue
A10200
A20250
B20300


Any suggestions?

View 1 Replies View Related

Compare Rows To Determine If Column Values Are Different?

Mar 2, 2011

I need to determine if a value for a group of rows is the same or different and I am not sure where to begin. I am fairly new to writing T-Sql code. I am working with SQL Server 2005. This is a work assignment; I am not a student.

I have two tables: One for Course and another for CourseDays. As the Course table implies, it lists courses for a school. The CourseDays tables has a row for each day a course is held. For instance, one course maybe held on Monday, Wednesday, and Friday, so there would be three rows, one row for each day. A given course could be held in a different room for each day. I am trying to write a query that returns one row for each course, and if the room number is the same for each day the class is held, return that room number in the row, else return 'Various'.

Course table:
CourseID, Desc
1 English
2 History
3 Science

CourseDays table:
CourseID, Day, RoomID
1 M 320
1 W 445
1 F 680
2 T 123
2 Th 123
3 M 514
3 T 514
3 W 521
3 Th 901
3 F 521

Expected results:
CourseID, Desc, RoomID
1 English Various
2 History 123
3 Science Various

I simplified the example, as there are about 30 columns in the table and about half a million rows.

View 14 Replies View Related

Having Rows With Some Null Values Returned Conditionally

Aug 8, 2012

This should be a simple solution, but it has been a long time since I've done any query writing (mostly in Oracle) and I am stumped, so here goes:

We are in the process of converting Access database to MSSQL with web form front ends.

I have a table, all columns are nullable, and want users to be able to query from a form, which has a field for each column and defaults to a % wild card for the entered value.

I want the users to be able to put any string in any field, and have it return each row that matches that, including rows with null values in the other columns, but not the column with the entered criteria.

Here is a sample of the data:

Code:
SQL> select * from test;

COL1 COL2 COL3 COL4
----- ----- ----- -----
this is a test
this is not test
this is not
this is test too
is test too
is too
is too

7 rows selected.

Now, if I have this SQL run, it will return only rows that have no nulls in any columns:

Code:
select
col1,
col2,
col3,
col4from test
where
col1 like'th%'
and col2 like '%'
and col3 like '%'
and col4 like '%';

COL1 COL2 COL3 COL4
----- ----- ----- -----
this is a test
this is not test
this is test too

Now, if I use an OR clause for each column, this mostly works, but the trouble is it will also return rows with null values for the field that has criteria entered in it:

Code:
select
col1,
col2,
col3,
col4from test
where
(col1 like'th%' OR col1 is null)
and (col2 like '%' OR col2 is null)
and (col3 like '%' OR col3 is null)
and (col4 like '%' OR col4 is null);
COL1 COL2 COL3 COL4
----- ----- ----- -----
this is a test
this is not test
this is not
this is test too
is test too
is too
is too

The idea is to only select the first 4 rows in the above example.

I was playing with ISNULL in the select clause, but all it does is substitute a string for a null, and I think CASE will do the same thing.

Is there a way I can write this query so it will return rows with NULL values in any column, except the one(column) that has user entered criteria in it?

View 9 Replies View Related

T-SQL (SS2K8) :: Getting Sum Values For Non Overlapping Rows By Datetime?

Oct 13, 2014

I want to count persons for non overlapping intervalls by room number. Here the data:

SET DATEFORMAT mdy;
DECLARE @PersonTime TABLE
(
ID INT,
Person INT,
Room INT,
Coming DATETIME,
Going DATETIME

[code]....

View 4 Replies View Related

T-SQL (SS2K8) :: Subtraction Of Values From Consecutive Rows

May 31, 2015

I've;

Id.........|......type....|.....Value
2001................1...............20
2001................2...............32
2002................1...............19
2002................2...............21
2003................1............... 3
2003................2...............30

I want;

Id........|.......Value
2001.................12
2002..................2
2003.................27

View 7 Replies View Related

T-SQL (SS2K8) :: Search Through Rows With Specific Values

Sep 16, 2015

I've a table that stores operationcode for each jobnumber. The jobnumber can have multiple operationcode. From the below DDL, I need to show all the jobs that have operation codes as 2001 and 2002. In the below DDL Jobnumber 80011 has both the operation codes 2001 and 2002 so this job will display on the report.

On the other hand Job 80021 only has operationcode 2001 and I do not want this job to show up on the report.

I need to show all the operationcodes for a job if it has operationcode 2001 and 2002.

USE tempdb;
GO
DECLARE @TEST_DATA TABLE
(
DT_ID INT IDENTITY(1,1) NOT NULL PRIMARY KEY CLUSTERED
, OperationCodeVARCHAR(10) NOT NULL
, EmployeeCode VARCHAR(10) NOT NULL

[Code] ....

View 9 Replies View Related

SQL Server 2014 :: Comparing Two Rows Values?

Oct 30, 2015

I need to compare two consecutive rows (if BEGDA of second row is 1 day greater than ENDDA of first row then I need to pick First row BEGDA and 2nd row ENDDA)

Input Table Data:

PERNRSUBTYBEGDAENDDA
1010429001/1/20081/15/2015
10104210001/1/200812/31/2008
10104210001/1/200912/31/2009
10104220001/1/20081/15/2008
10104220001/16/200812/31/2008
10104220001/1/200912/31/2009
10104230001/1/200812/31/2008
10104230001/1/200912/31/2009
10104230001/5/201012/31/9999
101042DDPP5/16/200712/31/2007
101042DDPP2/16/20075/15/2007
101042MAPP2/1/200712/31/2007
101042VISI3/1/200712/31/2007

Output should be like this:

PERNRSUBTYBEGDAENDDA
1010429001/1/20081/15/2015
10104210001/1/200812/31/2009
10104220001/1/200812/31/2009
10104230001/1/200812/31/2009
10104230001/5/201012/31/9999
101042DDPP2/16/200712/31/2007
101042MAPP2/1/200712/31/2007
101042VISI3/1/200712/31/2007

View 3 Replies View Related

Identity, Default Values And Multiple Rows

May 27, 2008

Howdy all,
I've run into an interesting scenario that I can't seem to resolve.

We have a table that we are using to create sequence ids. It's literally a table with a single field with the identity value turned on.

create table ident (seq_id int identity(1,1) primary key NOT NULL)


If I want to grab a new sequence id, I can execute

INSERT INTO
ident
DEFAULT VALUES
SELECT scope_identity() AS seq_id


All is well and good. However, now let's suppose that instead of just one, I'd like to get a range of values.

If the table had one other field in it, I could do the following

create table ident2 (seq_id int identity(1,1) primary key NOT NULL, placeholder char(1))
GO
;
WITH RECORDS AS
(
SELECT
CAST('A' as char(1)) AS col1
UNION ALL
SELECT
char(ascii(col1) + 1)
FROM
RECORDS
WHERE
col1 < 'C'
)
INSERT INTO
ident2
OUTPUT
INSERTED.seq_id
SELECT
NULL
FROM
RECORDS


Can this be done if there is only the identity column and if so, someone care to educate me?

View 10 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved