Showing posts with label field. Show all posts
Showing posts with label field. Show all posts

Friday, March 30, 2012

How to control format of datetime attributes?

There is an attribute that have type DateTime, based on the field type in data source. It hasn't separate name column. The member caption is formatted as yyyy-MM-dd hh:mm:ss. Can I control the format of Member name without giving separate name column.

I assigned different format in the format field of key property window, but it had no effect. What I did wrong?

Hello. I do not think that you will have to pay any penalty from adding a new column in the data source view with a new format of your date column. I recommend to use the TSQL function CONVERT that have arguments for different date formats. Have a look at CONVERT in Books On Line, and you will see the complete list of different codes/arguments for different date formats.

HTH

Thomas Ivarsson

|||

Thank you,

I thought about more sofisticated solution, that can be used in multi culture environment without adding x additional fields with "formatting" of a datetime attribute.

I hoped, that the AS2005 is smarter as AS2005 and offers more possibilties.

Do you know what is the format field in key properties for?

Wednesday, March 21, 2012

How to connect generic database field to report?

Hello,

I want to make a report where multiple users can use the same report to connect to their databases and then print out the report with information from those databases. Both databases have the exact same tables and fields but the data that is in them is different. However, I have only been able to figure out how to connect the report to one specific database, and therefore the report always prints out information from that database instead of the user specified one. So let's say I want my report to print out the name that is in the database field Name for any database I connect to, how would I do this?

Assuming SSRS 2005, you can use an expression-based connection string as demonstrated in the ExpressionBasedConnection sample report in this download. Since I think it is a no-no to pass the connection string as a report parameter, the report gets it from the Report Server config file.|||I looked at your samples but I'm not sure I quite understand them. It looks like your ExpressionBasedConnection report just connected to the database named AdventureWorks. But my reports are going to be connecting to databases that have the same underlying structure but with variable names that I won't know when creating the report. I will only know the name of the database when the user runs our software to connect to whatever database they use. But I still want to create a report that will use, for example, the Name, Address, State fields from the Customer table, but I don't want to hook it up to one specific database. How do I do this?|||

OK, but somehow the end-user has to specify the database name at some point, correct? Let's assume that the user will pass the database name as a report parameter. Then, you can use an expression-based connection string in the report data source (it must be private), to establish connection to that database.

Did I miss anything?

|||Yes at some point the user will specify what database they want to connect to but I don't think I fully understand how to use that database in the report. So let's say I want to add a dataset to my report by the name of Company. So in the Dataset tab of the report I select new dataset and I get to the Dataset dialog box. So I name the dataset Company. I go into the "Datasource connection" dialog box by clicking the ... button. I've created a parameter for the dataset call ConnectionStr, so therefore in the Connection String edit box, I type " = Parameters!Connection.Value". Then I click OK that dialog and return to the Dataset dialog box. For the query string I type "SELECT * FROM Company" and then click OK. So in the datasets toolbar, I can see a dataset named Company but it doesn't have any of the company fields in it like Name, Address, etc. How to I get these fields in the dataset so I can use them in my report? Since the report doesn't know what the ConnectionStr parameter is yet it doesn't seem like it will be able to do this.|||Start with a normal connection string. Click the Refresh Fields button on the Data tab in the Report Designer. Then change to an expression-based connection string.|||Alright, so I did what you suggested, but when I drag a field from the dataset I want it says First(Fields!Name.Value, "Company"), but I don't want a report that just prints the information of the first company in the dataset, I want a report printed for every company that is in the dataset after my query has been applied.|||This usually happens when the data region is bound to a different dataset than the one you are dragging the fields from. Take a look at the Dataset property of the data region and clear it (or set to Company). Then, you can re-drag your fields or remove the First function so the field reference is =Fields!Name.Value.|||So I've accomplished this, and now I am having a similar problem of connecting a generic data source to the reportviewer. When I'm in the Data Sources window and I select Add New Data Source, in order to add a new one, I have to select a specific database. But I don't want the reportviewer to connect to one specific data source, I just want it to print out the report that I have made following your tips, how do I do this?

how to confine a field to be number characters only?

i have a field which is CHAR(20), and it is allowed to only containe number chars.

is there any collation_name can help ? or how can i set the check clause ?

Here is a couple of ways that I would do it (no promises, and there could be better ways :)

DECLARE @.test char(20)
SELECT @.test = '12345678901234567890'

--All 20 characters are numbers
SELECT CASE WHEN @.test LIKE '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]' THEN 'Yes' ELSE 'No' END

--allows trailing blanks (that is what the replace to an ampersand does.)
SELECT CASE WHEN len(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(rtrim(@.test),' ','@.'),'0',''),'1',''),'2',''),'3',''),'4',''),'5',''),'6',''),'7',''),'8',''),'9','')) = 0 then 1 else 0 end

|||

You can also add a check constraint ot the table

CREATE TABLE TestNumbersOnly (SomeColumn char(20), CONSTRAINT NumericOnlyPlease CHECK (SomeColumn NOT LIKE '%[a-z]%' AND ISNUMERIC(SomeColumn) = 1))

Let's test
--Good
INSERT TestNumbersOnly VALUES ('12345678901234567890')
--Good
INSERT TestNumbersOnly VALUES ('1234567890123456789')

--Bad
INSERT TestNumbersOnly VALUES ('1234567890123456789A')
--Bad
INSERT TestNumbersOnly VALUES ('123(4567890123456789')
--Bad
INSERT TestNumbersOnly VALUES ('123-4567890123456789')

Denis the SQL Menace

http://sqlservercode.blogspot.com/

|||Why don't you use one of the numeric or integer data types then for the column? It is much cleaner, easier and efficient if you use the correct data type for the data. Using character data types has several issues in that you need to enforce your own constraints, the query optimizer doesn't know that the values are only numeric for example, and if you need to perform arithmetic operations then you need to cast the value explicitly & so on. Is there any business reason to store numeric values in character column? This is a problem with the data model and it is best it to deal it at that level.|||

well, the column is actually a one that is the IDs of customers, so i think it is conventionally to set it to CHAR. unfortunately for me, it is also conventionally that the IDs of customers containt only number characters, so the two convention contradict at this point !

after reading your suggestions, i think it is much wise to adopt only one of them, or to let the front-end do the check up

|||No, don't let the front end be the only check. Then it cannot be 100% trusted. Do something on the backend if you have the ability to add constraints.|||yes, that's always a problem! thx for the remainder

Monday, March 12, 2012

How to conditionally move field?

User enters a starting quarter and a year. I need to display 10 quarters and their years in line:
2005 . . . 2006
Q3 Q4 Q1 Q2 Q3 Q4 ...
Obviously, position of a year field will change based on whether we start from Q1 or from Q4.
Is there a way to do it?I'd probably put each variation in different sections and suppress each section accordingly.
Alternatively, use a non-proportional font and build up a string to display the year values with front space padding as required.

how to conditionally get the data

Hi,

In Reporting Service, how to conditionally get the data? Let's say, I don't want the line

when the Status field is "inactive" and Eff_Date<"1/1/2006"

I conditionally hided the Visibility of this line. But when i tried to get the subtotal, this line's Quantity info still was included into the subtotal.

I tried to use the Filter box of the dataset to do it, but don't know how.

Can anybody please help me out?

Thanks a lot.

What kind of datasource are you using?

Friday, March 9, 2012

How to concatenate two fields in a textbox one integer and other charecter field

I have the folliwing two fields, want tp concatenate:

=Fields!sequenceno.Value & =Fields!LogType.Value

Thank you very much for the information.

Convert the integer to a varchar explicitly.

Adamus

|||

Remove the second equals sign.

=Fields!sequenceno.Value & Fields!LogType.Value

How to concatenate multiple rows into one field?

Hi,

I hope someone here can help me.

We have a product table which has a many-to-many relation
to a category table (joined through a third "ProductCategory" table):

[product] --< [productCategory] >-- [category]
--- ------ ----
productID productCategoryID categoryID
productName productID categoryName
categoryID

We want to get a view where each product occupies just one row, and
any multiple category values are combined into a single value, eg
(concatenating with commas):

Product Category
------
cheese dairy
cheese solid
milk dairy
milk liquid
beer liquid

will become:

Product Category
------
cheese dairy, solid
milk dairy, liquid
beer liquid

What is the best way to do it in SQL?

Thanks and regards,
Dmitri"mitmed" <mitmed@.yahoo.com> wrote in message
news:c2fa9a07.0408182248.684dfd7a@.posting.google.c om...
> Hi,
> I hope someone here can help me.
> We have a product table which has a many-to-many relation
> to a category table (joined through a third "ProductCategory" table):
> [product] --< [productCategory] >-- [category]
> --- ------ ----
> productID productCategoryID categoryID
> productName productID categoryName
> categoryID
> We want to get a view where each product occupies just one row, and
> any multiple category values are combined into a single value, eg
> (concatenating with commas):
> Product Category
> ------
> cheese dairy
> cheese solid
> milk dairy
> milk liquid
> beer liquid
> will become:
> Product Category
> ------
> cheese dairy, solid
> milk dairy, liquid
> beer liquid
> What is the best way to do it in SQL?
> Thanks and regards,
> Dmitri

The usual answer is that you should do this in the client, not in TSQL, but
if you must then the only reliable way is using a cursor.

http://www.aspfaq.com/show.asp?id=2279

Simon|||Thanks for your reply Simon,

I completely agree with you that the best place for this type of code
is on the client side. The issue is that my client side is a Crystal
Report (in VB.NET) and i don't know how to do this kind of processing
there. The report i'm trying to produce is the list of products and
their details including categories a product belongs to. I would
really appreciate if somebody could point me to a good crystal report
resource, where it shows how to do things like that if it's possible.

Regards,
Dmitri

"Simon Hayes" <sql@.hayes.ch> wrote in message news:<4124eaa5_2@.news.bluewin.ch>...
> "mitmed" <mitmed@.yahoo.com> wrote in message
> news:c2fa9a07.0408182248.684dfd7a@.posting.google.c om...
> > Hi,
> > I hope someone here can help me.
> > We have a product table which has a many-to-many relation
> > to a category table (joined through a third "ProductCategory" table):
> > [product] --< [productCategory] >-- [category]
> > --- ------ ----
> > productID productCategoryID categoryID
> > productName productID categoryName
> > categoryID
> > We want to get a view where each product occupies just one row, and
> > any multiple category values are combined into a single value, eg
> > (concatenating with commas):
> > Product Category
> > ------
> > cheese dairy
> > cheese solid
> > milk dairy
> > milk liquid
> > beer liquid
> > will become:
> > Product Category
> > ------
> > cheese dairy, solid
> > milk dairy, liquid
> > beer liquid
> > What is the best way to do it in SQL?
> > Thanks and regards,
> > Dmitri
> The usual answer is that you should do this in the client, not in TSQL, but
> if you must then the only reliable way is using a cursor.
> http://www.aspfaq.com/show.asp?id=2279
> Simon|||You can do this very easily with the RAC utility/tool for S2k.
No sql coding required.

For info on concatenation over rows see:
http://www.rac4sql.net/onlinehelp.asp?topic=236

RAC v2.2 and QALite @.
www.rac4sql.net

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!|||mitmed (mitmed@.yahoo.com) writes:
> I completely agree with you that the best place for this type of code
> is on the client side. The issue is that my client side is a Crystal
> Report (in VB.NET) and i don't know how to do this kind of processing
> there. The report i'm trying to produce is the list of products and
> their details including categories a product belongs to. I would
> really appreciate if somebody could point me to a good crystal report
> resource, where it shows how to do things like that if it's possible.

We use Crystal in our system (and we hate it!), but we never let Crystal
near SQL Server itself. The "database" we tell Crystal about is text files
with all the columns. The actual queries are submitted from VB6, and then
we feed Crystal one of more recordsets, typically augmented with other stuff
that the VB code puts in.

Exactly how that translates to in VB .Net I don't know, although it is
possible to work with ADO Recordset if you use the OleDb .Net data
provider. Then again, who wants to use ADO recordsets if you are in .Net?

I should add that my notion of how we use Crystal is somewhat foggy. I
try to stay away from Crystal as much as I can.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp

How to concatenate constants and expressions in report field

I was receiving [BC30205] End of statement expected Error
when I tryed to concatenate:

=INT(AVG(Fields!HT.Value)/360) ":" &INT(AVG(Fields!HT.Value)/60)

Please hlp!
Thank you.

You must convert to a string type.

= CSTR(INT(AVG(Fields!HT.Value)/360))+":"+CSTR(INT(AVG(Fields!HT.Value)/60))

How to concate 2 ore more text fields into one field?

Hello,

I hope someone has already done this, but I have a table with a text column- example ColA, now i want to run a query to select the ColA in this table and combine the results of ColA into a ColB in another table.

Something like - Note: the codes below doesn't work!!

DECLARE @.ResultID as int
DECLARE @.AccID int
DECLARE _rows CURSOR
FOR SELECT AccID FROM tableA

FETCH NEXT FROM _rows INTO @.AccID

WHILE (@.@.fetch_status <> -1)
BEGIN

UPDATE TableB SET Report = Report + (SELECT txtField FROM tableA WHERE AccID = @.AccID)

WHERE AccID = @.AccID


FETCH NEXT FROM _rows INTO @.AccID

END

Thanks in advance

I tested something like this:(Assume you are using SQL Server 2000 text fields)

You can try it out in your code.

DECLARE @.ptr varbinary(50),@.ptr2 varbinary(50)

DECLARE @.len int, @.len2 int

update Table_B SET colB=(SELECT colA FROM Table_A where Accid=1) WHERE Accid=1

select @.ptr = TEXTPTR(colB), @.len=datalength(colB), @.ptr2 = TEXTPTR(report), @.len2=datalength(report) from Table_B WHERE Accid=1

UPDATETEXT Table_B.report @.ptr2 @.len2 0 Table_B.colB @.ptr

In SQL Server 2005, you can define Varchar(MAX) field, it will be a lot more easy to manipulate by using .WRITE function.

|||

Thanks Limno,

Sorry I could reply this sooner. This is one slick trick - appreciated.

However, I couldn't get this working as the way you have. Not sure what I am missing.

I kept having the error

Server: Msg 7116, Level 16, State 4, Line 13
Offset 17 is not in the range of available text, ntext, or image data.
The statement has been terminated.

DECLARE @.ResultID as int
DECLARE @.AccID int
DECLARE @.Heading varchar(255)
DECLARE @.ptrReport varbinary(16)
DECLARE @.ptrTmpField varbinary(16)
DECLARE @.Len1 int, @.Len2 int

SELECT @.ptrTmpField = TEXTPTR(tmpField), @.Len1 = Datalength(tmpField),
@.ptrReport = TEXTPTR(Report), @.len2 = Datalength(report)
FROM PHILTBL2 WHERE AccID = 1624728


UPDATETEXT PHILTBL2.Report @.ptrReport @.len2 0 tmpField @.ptrTmpField

Thanks

|||

If I changed the updatetext statement as

UPDATETEXT PHILTBL2.Report @.ptrReport @.len2 0 @.ptrTmpField

The error went away, but I get gebrish text in my report field.

Look like the textptr doesn't work

|||

Check this link that Jared Ko provided earlier today:

http://databases.aspfaq.com/general/how-do-i-concatenate-strings-from-a-column-into-a-single-row.html

|||

Thanks CetinBasoz, but the the problem I am dealing with is the text field and it's a different animal than varchar field. :-(

Check here for more info

http://msdn2.microsoft.com/en-us/library/ms189466.aspx

|||

Please see below scripts for some examples on how to use UPDATETEXT with TEXTPTR.

-- Script #1

/* To concatenate several binary values into one image field: */
create table #Bin ( SegmentID int IDENTITY ( 1 , 1 ) , Segment varbinary(2) )
insert #Bin values (0x11)
insert #Bin values (0x22)
select * from #Bin
go
declare @.imageptr varbinary(16), @.segmentid int, @.segment varbinary(16)
create table #AllBin ( Segments image null )
-- Get valid pointer first
insert #AllBin values ( 0x0 )
select @.imageptr = TEXTPTR( Segments ) from #AllBin
-- Set data to null
update #AllBin set Segments = null

select @.segmentid = -1
while(1=1)
begin
select @.segmentid = min(segmentid)
from #Bin
where segmentid > @.segmentid
if @.segmentid is null break

select @.segment = segment from #Bin where segmentid = @.segmentid

updatetext #AllBin.Segments @.imageptr null 0 @.segment
end
select * from #AllBin
go
drop table #Bin
drop table #AllBin
go

-- Script #2

create procedure #t (
@.t1 text , @.i1 image, @.t2 text, @.i2 image, @.t3 varchar(30), @.i3 varbinary(2)
)
as
declare @.tptr varbinary(16), @.iptr varbinary(16), @.tpos int, @.ipos int
create table #blob(id int identity, t text, i image)

insert #blob values(@.t1, @.i1)
select id, convert(varchar(50), t) as text_val, convert(varbinary, i) as image_val
from #blob

update #blob set t = @.t2, i = @.i2 where id = @.@.identity
select id, convert(varchar(50), t) as text_val, convert(varbinary, i) as image_val
from #blob

select @.tptr = TEXTPTR(t), @.tpos = PATINDEX('%TEXT...%', t) - 1,
@.iptr = TEXTPTR(i), @.ipos = 2
from #blob

updatetext #blob.t @.tptr @.tpos 0 @.t3
select id, convert(varchar(50), t) as text_val, convert(varbinary, i) as image_val
from #blob

updatetext #blob.i @.iptr @.ipos 1 @.i3
select id, convert(varchar(50), t) as text_val, convert(varbinary, i) as image_val
from #blob
go

exec #t 'SOME TEXT HERE...', 0x02498765bcde3,
'MODIFIED TEXT...', 0xab86ec64,
'(INSERT BEFORE TEXT) ', 0xcd -- replace 3rd byte

-- Inserted text & image value
/* id text_val image_val
-- -- --
1 SOME TEXT HERE... 0x002498765BCDE3
*/

-- Updated text & image value. This one replaces the existing values
/*
id text_val image_val
-- -- --
1 MODIFIED TEXT... 0xAB86EC64
*/

-- Modified text value only. This one inserts some text into the existing value
/*
id text_val image_val
-- -- --
1 MODIFIED (INSERT BEFORE TEXT) TEXT... 0xAB86EC64
*/

-- Modified image value only. This one changes a byte in the existing value
/*
id text_val image_val
-- -- --
1 MODIFIED (INSERT BEFORE TEXT) TEXT... 0xAB86CD64

*/
go
drop proc #t
go

Also, here is a link to a SP that show how to generate text value from multiple strings.

|||Sorry my bad. When I wrote it was around 3 AM here.

Wednesday, March 7, 2012

how to compare Time......... using DateTime field

hi guyz i want to compare time from DateTime field i.e. i want to identify if the time is from 1pm to 2pm the do this else do.....

select DATEPART(hour, loginTime) .....returns me the hour i can get the Hour part of the time but the prblem is how to identify it

whether it is less than 2:00:00 pm and greater than 1:00:00 pm i can do this task using at application level but i want this to b done at query level

any ideas????

i used following query..

my table is like Finddate

id bdate

1 2007-01-01 13:30:00.000
2 2007-01-01 14:30:00.000
3 2007-01-01 14:20:00.000
4 2007-01-01 23:30:00.000
5 2007-01-01 22:30:00.000

and i am selecting the records between 1 to 2 pm.

1 pm means 13 and 2 pm means 14, so i written query

select*from finddatewheredatepart(hour,bdate)>=13anddatepart(hour,bdate)<=14

this will gives me result as

id bdate

1 2007-01-01 13:30:00.000
2 2007-01-01 14:30:00.000
3 2007-01-01 14:20:00.000

hope this will help u..

|||

hi Mahadeomatre thnx for ur help i got the solution,ur query should b like this.

select*from finddatewheredatepart(hour,bdate) >=13anddatepart(hour,bdate)<14

then according to ur table it wil return only 1st row

1 2007-01-01 13:30:00.000

and "datepart(hour,bdate)<14" will omit the other two rows as per requirment.

2 2007-01-01 14:30:00.000
3 2007-01-01 14:20:00.000

How to compare if date is in between two dates.

I have a report that binds to view. Every record has an "Employee Joining date" date field with it.

I have to filter out records ; whose joining date is with in two different dates.

How will i set "selection Criteria"; as i dont have any idea of the crystal reports syntax.

SOme refrence or sample will be valuable for me.

PLz. reply soon

Thanks in advanceGive the folg. in ur selection formula

{join_date} in {?start} to {?end}

join_date => ur database field

start, end => parameter fields

Hope this will work|||what i see is that the date in crystal report is consist of time too...
so how to get rid of the time, so that i can get only the date?|||what i see is that the date in crystal report is consist of time too...
so how to get rid of the time, so that i can get only the date?

Use Cdate Function

Cdate(DateTimeField)

Friday, February 24, 2012

How to Combine Multiple Rows Data into single Record or String based on a common field.

Hellow Folks.

Here is the Original Data in my single SQL 2005 Table:

Department: Sells:

1 Meat

1 Rice

1 Orange

2 Orange

2 Apple

3 Pears

The Data I would like read separated by Semi-colon:

Department: Sells:

1 Meat;Rice;Orange

2 Orange;Apple

3 Pears

I would like to read my data via SP or VStudio 2005 Page . Any help will be appreciated. Thanks..

Hi,

you can use the following Function in SQL server:

USE NORTHWIND
GO

CREATE FUNCTION ProductList (@.CategoryIDINT)
RETURNSVARCHAR(1000)
AS
BEGIN
DECLARE @.ProductsVARCHAR(1000)

SELECT@.Products =COALESCE(@.Products +', ','') + ProductName
FROM Products
WHERE CategoryID = @.CategoryID
ORDER BY ProductNameASC

RETURN @.Products
END
GO

SELECTDISTINCT CategoryID, dbo.ProductList (CategoryID)AS ProductList
FROM Products
GO

 
and this is based on your table: 
 
USE NORTHWINDCS
GO

CREATE FUNCTION ProductList (@.CategoryIDINT)
RETURNSVARCHAR(1000)
AS
BEGIN
DECLARE @.ProductsVARCHAR(1000)

SELECT@.Products =COALESCE(@.Products +', ','') + sells
FROM table1
WHERE Department = @.CategoryID
ORDER BY sellsASC

RETURN @.Products
END
GO

SELECTDISTINCT Department, dbo.ProductList (department)AS ProductList
FROM table1
GO

thanks

|||

SharpGuy, your solution works. Thanks and have a great Thanksgiving...

how to combine fromdate and todate values in one field

Hi All,

I have to fetch FromDate and Todate values from the table like this.Suppose Fromdate value is 02-Feb-2007 and Todate Value is 04-Feb-2007,then my need is to get the date value like this.....Feb 2-4,2007or 2-4 Feb,2007.Can anybody know the syntax or code?.I am using sql Server and fromdate and todate values are stored in two different feilds in table.

Thanks and Regards

This seems to be a duplicate post? I posted an answer in the other post, here it is again. This assumes two columns: from_date and to_date. If it fixes your problem mark one or both as answered!

Selectconvert(varchar(2),DatePart(day, from_date)) +'-' +convert(varchar(2),DatePart(day, to_date))+' '+substring(convert(varchar(12), to_date, 106), 4, 8)from [yourtable]

How to combine 2 records into 1 unique record

Hi all,

We have an app that uses SQL 2000. I am trying to track when a code field
(selcode) is changed on an order which then causes a status field (status)
to change. I tried a trigger but the app may use 2 different update
statements to change these fields depending on what the user does. When the
trigger fires (on update to selcode), the status field has already been
changed. So my trigger to record the changes from inserted and deleted do
not get the true 'before' value of the status field.

The app does use a log table that tracks these changes. The problem I am
having is that 2 records are created, one for the change to selcode and
another for the change to status.

I am looking for help with a script to combine the existence of these 2 log
records into 1 unique record or occurance that I can track.

example:
ordlog: table that logs order changes
ordernr: order number
varname: name of field being changed
old_value: contents of field before change
new_value: contents of field after change
syscreated: date/time of log entry

SELECT ordernr, varname, old_value, new_value, syscreated
FROM ordlog
where varname = 'selcode' and ordernr = '10580'

SELECT ordernr, varname, old_value, new_value, syscreated
FROM ordlog
where varname = 'status' and ordernr = '10580' and old_value = 'A' and
new_value = 'O'

So I need a way to combine these 2 log entries into a unique occurance. The
ordernr and syscreated could be used to link records. syscreated always
appears to be the same for the 2 log entries down to the second. Selcode
can change from NULL to a number of different values or back to NULL.Status
is either 'A' for approved or 'O' for open. An order can have many log
entries during its life. The selcode may be changed several times for the
same order.

Ideally, I would like a result that links 2 log entries and shows the status
changed from 'A' to 'O' when selcode changed.

Thanks for your time.rdraider (rdraider@.sbcglobal.net) writes:

Quote:

Originally Posted by

SELECT ordernr, varname, old_value, new_value, syscreated
FROM ordlog
where varname = 'selcode' and ordernr = '10580'
>
>
SELECT ordernr, varname, old_value, new_value, syscreated
FROM ordlog
where varname = 'status' and ordernr = '10580' and old_value = 'A' and
new_value = 'O'
>
>
So I need a way to combine these 2 log entries into a unique occurance.
The ordernr and syscreated could be used to link records. syscreated
always appears to be the same for the 2 log entries down to the second.
Selcode can change from NULL to a number of different values or back to
NULL.Status is either 'A' for approved or 'O' for open. An order can
have many log entries during its life. The selcode may be changed
several times for the same order.
>
Ideally, I would like a result that links 2 log entries and shows the
status changed from 'A' to 'O' when selcode changed.


Could this do:

SELECT a.ordernr, a.syscreated,
oldselcode = a.old_value, newselcode = a.new_value,
oldstatus = b.old_value, newstatus = b.new_value
FROM ordlog a
JOIN ordlog b ON a.ordernr = b.ordernr
AND datediff(seconds, a.syscreated, b.syscreated) <= 1
WHERE a.varname = 'selcode'
AND b.varname = 'status'
AND coalesce(a.old_value, '') <coalesce(a.new_value, '')
AND a.old_value = 'A'
AND b.new_value = 'B'

Note: this is an untested query.

If the does not return the expected results, I suggest that you post:

o CREATE TABLE statments for the involved table(s).
o INSERT statements with sample data.
o The desired output given the sample.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx

Sunday, February 19, 2012

How to choose next value for identity column

Hi,

I have a table with its ID field set as an Identity column with "seed" and "increment" set to 1. Now, I have rows in there that I don't want to change. I'd like the next addtitions to the table to start at a specific value for their ID columns.

Basically, how can I specify a new starting value for an identity column?

Thanks,

Skip.I found this in SQL Server books online as well as the web. This sounds like what you might be looking for.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_dbcc_5lv8.asp