Transact SQL :: How To Identify When There Is A Break In Continuity Of Integer On A Column
Jul 16, 2015
I have two columns, one column has a document ID and a given document can have many pages. The second column has the pages. Now I want to find out when the page number is broken. For example, if doc ID 1 has 3 rows and each of the three has 1,2,3 and then the fourth row has document 1 but the value jumps from 3 to 7 and then goes to 8,9,10 and then jumps again and starts from 17, i want to have the ranges identified.
DocID Page NumberÂ
1 Â Â 1
1 2
1 3
1 7
1 8
1 9
1 10
1 17
1 18
1Â 19
1 Â Â 20
The result should look like :
DocID Page NumberÂ
1 Â 1-3
1 Â Â 7-10
1 Â 17-20
View 4 Replies
ADVERTISEMENT
May 7, 2015
Imagine I set a begin transaction on table a and updating a row and not committed and not roll backed--first connection
From second connection I am selecting same table (obviously it wait until first connection commits/rollback based on my transaction level: my isolation level is read committed).
1. How do I know second connection is to waiting to first connection to complete.
2. If I want to select rows that are not locked by update process how do i need to do(ex:row 1,2,3,4 and 1 is locked by update process(exclusive lock) and i want to leave that and i need to select 2,3,4 records).
View 6 Replies
View Related
May 17, 2015
I have the following shift table:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
[code]...
I need to identify which shift is currently running on by providing the current time.I used the following query to get the result. It is giving correct result for Morning & Afternoon Shift but failed to produce result for Night Shift.
SELECT ShiftName, Shiftid
FROM WHShifts
WHERE DATEPART(HOUR, @Currenttime)>=(DATEPART(HOUR,CAST(ShiftInTime AS Datetime))) AND DATEPART(HOUR, @Currenttime)<=(DATEPART(HOUR,CAST(ShiftOutTime AS Datetime)))
Is there any way to find out the night shift from a given time.
View 15 Replies
View Related
Aug 18, 2015
I have a table with multiple rows per staff person. Each of these rows has staff_id, start_date, and end_date. Per staff, if any start_date comes between the start_date and end_date of a different row, or if any end_date comes between the start_date and end_date of a different row, then I have to flag these records as being identical.Â
How can I do this? I have tried doing a Cross Apply because I thought that would do Cartesian product (comparing every row), and I've also tried temp tables. But I haven't gotten either of these to work. Here is some dummy data:
if exists (select * from tempdb.dbo.sysobjects o where o.xtype in ('U') and o.id = object_id(N'tempdb..#staff_records')
) DROP TABLE #staff_records;
create table #staff_records
(
staff_id varchar(max),
[Code] ....
View 12 Replies
View Related
Apr 23, 2015
I've attempted to identify a primary and foreign key in these two tables, but I am getting a bunch of errors re duplicate keys and column names needing to be unique.Perhaps the primary and foreign key I have identified don't meet the criteria?
CREATE TABLE StockNames
(
-- Added Primary key to [stock_symbol]
[stock_symbol] VARCHAR(5) NOT NULL CONSTRAINT PK_stock_symbol PRIMARY KEY,
[stock_name] VARCHAR(150) NOT NULL,
[stock_exchange] VARCHAR(50) NOT NULL,
[code].....
View 19 Replies
View Related
Mar 18, 2007
In my report i would have 2 groups.
The first group should cause a real page break, the secound group should cause a column break.
Any idea on how to realize this, i've been playing with quite some settings but .....
So, any help ...
View 1 Replies
View Related
Jul 14, 2015
I have a table with 100 rows, 1 field (ID), and I would like to write a query to output it as 4 rows, and 25 columns.
Row data
ID
1
2
3
4
5
6
7
8
9
...
98
99
100
Output will be like
c1Â c2Â Â c3Â Â Â c4Â Â Â c5....
1Â Â Â 5Â Â Â 9Â Â Â Â Â 13
2Â Â Â 6Â Â Â 10Â Â Â 14
3Â Â Â 7Â Â Â 11Â Â Â 15
4Â Â Â 8Â Â Â 12Â Â Â 16
View 4 Replies
View Related
Sep 3, 2007
Hi There
This one has bothered me ever since sql server 2000.
When you do an insert into a table with literally hundreds of char or varchar columns and you get the error that the insert failed due to data loss/truncation on a column.
Is there anyway in 2005 to actually find out what column ? Since there are hundreds is is literally a long process of going though each column 1 by 1 manually.
The database engine surely MUST know what column this occurred on so why can it not tell you which column the truncation occurred on ?
Can this be done in 2005 if not will this information be available in 2008 ?
Thanx
View 7 Replies
View Related
Oct 12, 2015
I am trying to break down the content based of hourly basis. It works fine when there are values for that specific hour but if there are entries or values for a specific hour then it returns null instead of 0. How not to get null instead get zero.
Here is the code below:Â
With temp_exp As
(Select pl.state,Cast(signeddate As date) As signatureDate, signeddate As DoneTime From contract c with(nolock) where c.signeddate>DateAdd(Day, Datediff(Day,0, GetDate()), 0)
)
Select
Sum(Case When CONVERT(varchar(8),DoneTime,108) Between '07:00:00' And '07:59:59' Then 1 Else 0 End) '8AM',
[Code] ....
View 3 Replies
View Related
Oct 12, 2015
I am trying to create a whole number DAX calculated column that is derived from a date column. Basically it gets the date from the source data column and outputs it as an integer in the YYYYMMDD format.So 01/OCT/2015 would become --> 20151001...I've been fidgeting with DAX but my problem is that I keep missing the leading zeroes for months and days. So 01/March/2015 becomes 201531 which is not what I want (I need 20150301 in this case).
View 2 Replies
View Related
Aug 5, 2013
I have this datetime:Â '2002-12-20 11:59:59'
I want to convert this to date (yyyy-mm-dd) to integer
This works fine for:Â SELECT CONVERT(INT, GETDATE())
But it doesn't work here:Â SELECT CONVERT(INT, '2002-12-20 11:59:59')
I want to convert date to integer without passing through any varchar conversion/result.
View 6 Replies
View Related
Nov 23, 2015
Given a 4 byte integer, how to extract each individual byte and format with a period separating them? As an example, if MSB is 1, followed by 2, then 3 then 4 then how can the four bytes from this integer be formatted and displayed as 1.2.3.4?
View 15 Replies
View Related
Jan 20, 2006
hi,
I have a huge db with many services ,users and applications hitting the db.
Suddenly one of our column is nullified , we are not able track who /how it is done,
Can any one tell be whatz the best way to identify this????
trace(what events to select ), trigger or what????
Thanks,
srini
View 2 Replies
View Related
May 10, 2007
Okay, I now have some dynamic SQL working. This is the SQL statement I have for a report in Reporting Services:
DECLARE @SQL nvarchar(4000)
SET @SQL=(SELECT AdHocSQL
FROM RptValueTypeMap
WHERE RptValueTypeMap.SectionCd in ('ITEM0010'))
EXECUTE (@SQL)
We have a table set up that actually holds different SQL statements based on the report items. This is reading the SQL statement from AdHocSQL for the Report item #0010 and it is returning the results. However, it does return the correct value, but under (No Column Name). I have tried to incorporate an "AS", but I get errors when I try this.
I am familiar, but new to SQL statements and I would like this to return a field so I can use this value in the report. What do I need to do?
Thanks for the information.
View 1 Replies
View Related
May 30, 2007
I have a question and excuse me if I look dumb ... but I can't MIRROR MASTER or other dBs. If I lose the server then (primary) ... will the db still be open? do I not require some of these non-mirrorable database to run?
View 3 Replies
View Related
Jul 6, 2006
I have a column look like this
Name
----------------------
John^Smith^P^^^^
Peter^Johnson^M^^^^
Joe^Tedone^^^
I want to break this column in to three as follow
FirstName LastName Middle
----------------- ----------------- -------------
John Smith P
Peter Johnson M
Joe Tedon
'^' is the delimiter, how can I do this? some one please help me out, thanks a million
View 9 Replies
View Related
Mar 21, 2008
I don't wnat SQL's Identify column's format ( which is 1�2�3 ...)I want my Prikey column is looks like starts in 0000000001�0000000002�0000000003....I set the Prikey columns type is Char(10) not nullis it possible to setting my identify column as I want?
View 15 Replies
View Related
Mar 1, 2002
Hi, I want to know how to remove identify property from a column without recreating the whole table...
When I do it in Enterprise Manager, it actually drop and recreate the table
in background. I just like to know if there is other way without recreating the tables. Thanks!
Xiao Tan
View 4 Replies
View Related
Apr 1, 2008
Been poking around, but how can I tell if a an identity column exists in a table?
View 10 Replies
View Related
Apr 18, 2008
DECLARE @EffLevels TABLE (ChangePoint int, Value Int)
INSERT@EffLevels
SELECT'1000', '767' UNION ALL--Changed
SELECT'1000', '675' UNION ALL
SELECT'1001', '600' UNION ALL--Changed
SELECT'1001', '545' UNION ALL
SELECT'1001', '765' UNION ALL
SELECT'1000', '673' UNION ALL--Changed
SELECT'1002', '343' UNION ALL--Changed
SELECT'1002', '413' UNION ALL
SELECT'1002', '334' UNION ALL
SELECT'1001', '823'--Changed
-- My Result should be
-- ChangePointPrevChangePointValue
-- 1000Null767
-- 1001 1000 675
-- 1000 1001 765
-- 1002 1000 343
-- 1001 1002 823
Any suggestion ?
View 9 Replies
View Related
Nov 1, 2007
Hi Every One,
I have a simple matrix like below
Categories
A
Total A
B
Total B
Products
SHOES
$100
$100
$50
$50
SOCKS
$80
$80
$90
$90
How can I add a Columns Group page break for the Group Categegory in Reporting Services 2005 so the first page break takes place after Total A and rest of the data moves to the next page?
View 1 Replies
View Related
Sep 5, 2007
I am interested for tips/pointers on Remote Data replication using SQL 2005. Let's say there are 2 sites (A and B). I plan to have site A comprised of 2 SQL servers (1 active and 1 on standby). Site B will have the same configuration. If site A becomes disasterous then Site B will come up with zero loss of data or minimal loss of data. Will SQL data replication provide solution? or I need to look at other methods. By the way, both sites have servers attached to SAN storage. Thanks in advance;
View 6 Replies
View Related
Jan 30, 2006
Hey folks,
I have a 2 column report that is not page breaking the way I would like. The report has a list that is grouped by a "Type" field. The header includes this type, though I had to use an aggregate of the report field like:
=Max(ReportItems!PlanType.value) & " Contacts"
I want a brand new page when the type changes, but since RS treats columns like pages, if my type ends in the first column, the new type begins in the second column. Is there any way to force it to leave that column blank and start a brand new page?
View 4 Replies
View Related
Sep 30, 2015
I would like to INSERT an array of integer into a table in MSSQL Server, then count the number of rows in the table with c++ using ODBC. Here you find my code to do this task:
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include<tchar.h>
#include <sql.h>
#include <sqlext.h>
#include<sqltypes.h>
[Code] ....
In my code, I would like to Insert the array and then count the number of rows:
SQLTCHAR Statement[] = _T("INSERT INTO information1(Wert1,Wert2) VALUES(?,?) select count(*) as a from information1 ") ;
Problem : My expectation is, that first 9 rows are inserted into table then comes 9 as result to user (if the table is empty) but this code returns me 1 if first the table is empty. If the table is not empty, it returns 1+number of  existing rows in the table. If I take a look inside the table, the 9 rows are successfully inserted in it. Only the number of rows in the table is wrong.
Hint : If I monitor the database using SQL Profiler. It looks like this:
Why this statement doesn't work correctly?
View 7 Replies
View Related
May 6, 2015
Can I put a constraint on an integer column that will only allow a certain range of numbers to be entered, or do I have to put that into the application layer only?
I'd like the range to be 0 to 30 as the only allowable values. The only thing that I could think of was to create another table and populate with 0,1,2...,30 and put a foreign key on the new column that wouldn't allow anything not in that list but I was wondering if there was a better way.
View 3 Replies
View Related
May 27, 2007
When I use the PageBreakAtEnd on the table or on a group in the table, all it does is create a new column of the column report.
I'd want it to start a new page, how can I do this ? Should I work around this issue using code ?
Background: What I need to achieve is a report with 2 columns where the list of products in category 1 are listed in the left column and then snake to the 2nd column on the same page, then to column 1 on page 2, column 2 on page 2, etc...
When it comes to category 2, it should start a fresh new page regardless of whether the previous product was rendered in column 1 or column 2.
I get the snaking to work using the "Columns" property of the report Body. However page breaks do not start a new page, they just start a new column.
View 27 Replies
View Related
Jan 22, 2008
Hi out there
It seams that I have run into a know and apparently unsolved problem.
How do I force a page break, not column break, on a multi-column report?
I have 4 columns, my data is grouped and is setup to page break after each group.
But all I get is a column break, due to RS thinking of column's as pages.
Several people have posted about the same problem, but I can't find a solution. See...
http://forums.microsoft.com/TechNet/ShowPost.aspx?PostID=884945&SiteID=17
http://forums.microsoft.com/TechNet/ShowPost.aspx?PostID=226045&SiteID=17
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1654050&SiteID=1&pageid=0
http://www.themssforum.com/SVCS/Page-break-77428/
http://www.themssforum.com/SVCS/Createing-real/
http://www.bokebb.com/dev/english/2008/posts/2008116837.shtml
Does anyone know how to solve this ???
View 4 Replies
View Related
Aug 7, 2004
Hi everyone....
I need a column in my table that its DataType should be as integer arrays how can I implemant it in my sqlserver table.
Any help appreciated.
View 5 Replies
View Related
Oct 25, 2006
When I use the AVG Function on an integer column, the result is truncated
Example:
Select AVG(field1) from table1
Field1 is an int field and has 4 rows with the values 114,115,115 and 115. This will return 114.
I can get the correct result by using the following SELECT:
SELECT CAST(AVG(CAST (field1 as decimal(18,1)))+ .5 as int) from table1
Am I missing something here? Is there an simpler way to do this?
Any help will be appreciated.
Steve D.
View 6 Replies
View Related
Nov 16, 2015
We are facing problem in doing page break with column grouping. Our column group contains years e.g 2011, 2013 . We want to show a complete page for a year.Â
Suppose 2011 has 10 records(horizontal) and 2013 has 12 records(horizontal) in column. The output should be 10 records of 2011 in first page, 12 records of 2013 in second page.
We cannot change the report layout to make column to row and vice versa.
View 3 Replies
View Related
Feb 12, 2004
I have the following query:
SELECT AVG(respondent_question.answer)
Now, the 'answer' column is an integer. However, I want the query to return a floating point number with one decimal place (i.e., 5.4, 2.3)
Since the column is an integer, the query returns only an integer by rounding to the nearest integer. How can I do this? Thanks!
View 1 Replies
View Related
Jul 3, 1999
I need to add a column that has the datatype of integer with a seed and identity increment to a table that already exists and has data in it - and can't all NULLs. I have heard that this not possible if the table already exists.
I have downloaded the demo's of SQL Programmer and a couple of Embarcadero programs to see if that would help, but have had no succes to date.
Thanks for any help,
Alan
View 2 Replies
View Related
Dec 1, 2011
I want to display the following output where integer value is column data.
{[Advertiser].[AdvertiserKey].&[4000],
[Advertiser].[AdvertiserKey].&[4001],
[Advertiser].[AdvertiserKey].&[4002],
[Advertiser].[AdvertiserKey].&[4003],
[Advertiser].[AdvertiserKey].&[3661],
[Advertiser].[AdvertiserKey].&[3662]
}
View 4 Replies
View Related