|
Sorry I failed on making this point. The original question should be to find gaps and overlaps. Good point! Thanks!
|
|
|
|
|
Ok, this one works with your example: No it doesn't, it'll give you the combined stretches of road with gaps between them
WITH t1 AS (
SELECT r1.RoadID,r1.BEGIN
FROM Roads r1 Left outer join Roads r2
ON r1.RoadID = r2.RoadID
AND r1.BEGIN > r2.BEGIN
AND r1.BEGIN <= r2.END
GROUP BY r1.RoadID,r1.BEGIN
HAVING Count(r2.BEGIN) = 0
)
,t2 AS (
SELECT r3.RoadID,r3.END
FROM Roads r3 Left outer join Roads r4
ON r3.RoadID = r4.RoadID
AND r3.END >= r4.BEGIN
AND r3.END < r4.END
GROUP BY r3.RoadID,r3.END
HAVING Count(r4.BEGIN) = 0
)
,ContiguousStretch AS (
SELECT t1.RoadID,t1.BEGIN,Min(t2.END) AS END
FROM t1 join t2
ON t1.RoadID = t2.RoadID
AND t1.BEGIN <= t2.END
GROUP BY t1.RoadID,t1.BEGIN
)
,Gaps AS (
SELECT RoadID
FROM ContiguousStretch
GROUP BY RoadID
HAVING Count(RoadID) > 1
)
SELECT c.RoadID,BEGIN,END
FROM ContiguousStretch c join gaps g
ON c.RoadID = g.RoadID
ORDER BY c.RoadID,BEGIN
|
|
|
|
|
|
Take two, this one works with both overlaps and gaps and with no contiguous results:
WITH ordered AS(
SELECT RoadID,BEGIN,END,ROW_NUMBER() OVER(PARTITION BY RoadID ORDER BY BEGIN) as rn
FROM roads
)
SELECT o1.RoadID,o1.BEGIN,o1.END
FROM ordered o1,ordered o2
WHERE o1.RoadID = o2.RoadID
AND o1.rn = o2.rn -1
AND o1.END <> o2.BEGIN
UNION
SELECT o2.RoadID,o2.BEGIN,o2.END
FROM ordered o1,ordered o2
WHERE o1.RoadID = o2.RoadID
AND o1.rn = o2.rn -1
AND o1.END <> o2.BEGIN If you want only the gaps or only the overlaps you vill have to change the conditions in o1.END <> o2.BEGIN
|
|
|
|
|
Thanks, Jörgen! BTW, I have been to Sverige (Göteborg, Stockholm, and Malmö) ten years ago. Beautiful places. I liked it there.
|
|
|
|
|
You could try something like the following
SELECT a.*, b.*
FROM TableName a,
TableName b
WHERE a.roadid = b.roadid
AND b.start = (SELECT MIN(c.start)
FROM TableName c
WHERE c.roadid = a.roadid
AND c.Start > a.start)
AND a.End <> b.Start
ORDER BY ...
|
|
|
|
|
I appreciate your help. Thanks!
|
|
|
|
|
I'm at the last stage of a complete overhaul of our build scripts and I'm down to one last issue.
I can't seem to use sqlcmd to execute a create procedure statement that has a raiserror command in it. sqlcmd pre parses out the command and fails without executing. There doesn't seem to be any documented escape that I can figure out.
|
|
|
|
|
Just made a test with this and didn't have any problems. Could it be that you're having problems with for example apostrophes in the script in the RAISERROR statement.
The test script I used was:
create procedure ptest as
begin
raiserror( 'message', 10, 10 );
end;
go
and the command:
sqlcmd -S .\instancename -E -d dbname -i testproc.txt
Could you post the error message and the part of the script that's causing problems. Also have a test drive with the script above to see if it also causes the same problem.
|
|
|
|
|
I simply searched on here for code to finish a much over due uni ap assignment, now where all this hostility comes from I dont really know, mostly on to finish moi ap tell you the code works, apparently no one gets gleeful when finishing an ap that will progress them into their real life,
I dont see moi self as a programmer nor a even an avid enthusiasts in programming thinking I better post something being that I wasnt planning to even join this jest to getthe code
DO NOT FLOOD MOI EMAIL BOX: WITH INSULTS...
direct Q's that I cannot answer directly plese direct them somewhere else
usernameshelby@hotmail.com
|
|
|
|
|
Well shelby this not an insult but an observation. You posted this in a database forum, I presume you want something to do with a keyboard.
You did not actually post a question just a minor rant about how you were treated.
I also assume you have cross posted this, I suggest you read the forum guidelines on how to post a question to get a sensible answer.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
It wasnt a rant I dont know what you mean, besides more of a praise report so I dont get an incomplete! I have to complete jest develop five apps that work that isnt jest
I have a problem with you trying to observe someone like Im in an observatory I cannot approve....I dont know anything pertains to guidelines...
|
|
|
|
|
English is obviously not your strongest language because your sentences do not make sense, I suggest you get someone with reasonable english to help you frame your questions.
See the yellow highlighted post at the top of the page, go read that, it will help you ask a valid question.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Shelby. Which country are you really from? We may be able to get somebody from your country with a fuller grasp of English to help form a question that we can answer.
|
|
|
|
|
Smells like a Troll
I don't speak Idiot - please talk slowly and clearly
'This space for rent'
Driven to the arms of Heineken by the wife
|
|
|
|
|
UH excuse moi I dont know exactly you guys get off topic, this thread jest on the code for the virtual keyboard I dont like to ver off topic, So I dont know what youre trying to say either youre all out to play a mean prank nor a harmless joke...I dont know I care to be apart of...
|
|
|
|
|
hi..
the below is my SP..
i want to pass the parameter @name to the open query
but it is showing the error
incorrect syntax near '+'
ALTER PROCEDURE [dbo].[cub]
@name nvarchar(50)
AS
BEGIN
SET NOCOUNT ON;
select * from OPENQUERY(XHMNDGHFYUHFGHJFFRJF,'select {[Employee].[Dept].[Dept]*[Employee].[Empno].[Empno]} on 1,
[Measures].[Salary] on 0 from [Employee] where [Employee].[Empname].&'+ @name +' ')
END
if i pass the value directly..
like this.. where [Employee].[Empname].&vasu ')
it will execute fine..
but through the parameter name it will show error..
help me..
|
|
|
|
|
|
You have several options for this and they all have their downsides. Here's few.
One way is to create the statement and concatenate the parameter values to a string variable. After that you can execute the contents of the variable using EXEC[^]. This may lead to problems when dates, numbers etc are used in the parameters.
Another option is to create a permanent or temporary table and insert the parameter values to this table and join the openquery to this table. Of course you can use other conditions also (exists, 'column returned by openquery' < 'value in temp table' etc etc). Now you can build a data-type safe solution but you may encounter performance problems.
|
|
|
|
|
hi,
when we pass the parameter , not need of the quotes.
for eg:
without param
select * from employee where ename='sss';
with param
Declare en as varchar(5);
set en='wowow';
select * from employee where ename=@en;
Good luck.
|
|
|
|
|
Hi, guys
We encountered a SQL server error message saying, "String or binary data would be truncated". I know it's because some new records to be inserted into a table has value exceed the limit of the column's definition, eg, the value to be inserted is something like "abcdef", but the column's definition is something like "varchar(3)". The problem is, there are more than 10 tables that have been inserted new records in that stored proc, and each has huge amount of columns. Is there a way to let SQL Server tell exactly which table and which column it complains about? So I can avoid the extremely tedious task of using the same problematic data to examine each column?
Thanks very much,
|
|
|
|
|
I don't know, so I Googled for "String or binary data would be truncated" .
One of the hits[^] looks promising, especially the reply by Axos_Tech.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Thanks, but I cannot see how Axos_Tech's words actually help me in our situation. The post you gave has some words I quite agree: "This is notorious error in SQL." and "didn’t find any elegant way of finding this error." I think, this is one thing MS's dev failed the good practice here
|
|
|
|
|
Since it's an error you should get more info along the message. The whole message should include also the row number for the error so using you should be able to locate the statement. An example of the error:
Msg 8152, Level 16, State 14, Line 11
String or binary data would be truncated. So in that case the error was in the statement at line 11.
On the other hand, by using try-catch[^] block you can catch the error and produce more information about the error (like the statement, parameter values etc) for example using RAISERROR[^] statement
|
|
|
|
|
Ok I have a report list item. this list has textboxes etc inside it and is 7 inches tall. My question is the behavior seems to be that the list repeats by putting the next one underneath it and so on which results in one list showing per page.
What I wish to do is repeat that same list from left to right filling the possible space that way BEFORE dropping down to the next page. With the page in landscape, this would put 3 lists on one page before going to page 2.
So instead of
LIST
ITEM NAME
ITEM NUMBER
page down
LIST
ITEM NAME
ITEM NUMBER
page down
I would like to see
LIST LIST LIST
ITEM NAME ITEM NAME ITEM NAME
ITEM NUMBER ITEM NUMBER ITEM NUMBER
page down
To be clear this list has many more things than those two. that is just for visual reference. Its a very structured list with around 25 items in it including some images . Everything inside the list is out of a database, nothing static.
I have poked, prodded and read until my eyes bleed and either I'm missing something so simple I need to be shot, or this is something not normally done in a report.
This report is embedded in an ASP.net app but I posted here since the issue is with the structure of the report itself, nothing really dealing with asp.net
Programming is a race between programmers trying to build bigger and better idiot proof programs, and the universe trying to build bigger and better idiots, so far... the universe is winning.
|
|
|
|