Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Join Query Help

Author  Topic 

emmim44
Yak Posting Veteran

65 Posts

Posted - 2012-07-13 : 05:05:46
Hi all, the below query outputs an historical data for all columns in unsaccountB tbl. I need to add the current value (whatever is stored on outputed columns on unsaccountB tbl) of all outputed columns (dbc.ColumnName). How would I do that? Do you need any other info to help me with this thread?

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-07-13 : 10:32:22
is there a bit field which indicates current data? or is it based on latest date value?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

emmim44
Yak Posting Veteran

65 Posts

Posted - 2012-07-13 : 10:56:34
quote:
Originally posted by emmim44

quote:
Originally posted by visakh16

is there a bit field which indicates current data? or is it based on latest date value?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/




There is none.
Basically there should be another column "CurrentValue" and should be output the current value of outputed table column...UnsAccountB table columns are the same as DialogColumn tbl columnName field. Basically the current data is stored on unsaccountB tbl. DialogWatchPropery and DialogWatchOperation contain historical data and dialogColumn contains db tables structure information.

sample:
columnName CurrentValue oldValue
AccountDisabled F T
AccountDisabled T T

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-07-13 : 23:57:31
can you post table structures with some sample data?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

emmim44
Yak Posting Veteran

65 Posts

Posted - 2012-07-15 : 13:19:59
quote:
Originally posted by visakh16

can you post table structures with some sample data?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/




Which tbl are u referring?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-07-15 : 23:28:07
your tables which gives you above output

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

emmim44
Yak Posting Veteran

65 Posts

Posted - 2012-07-16 : 05:46:33
quote:
Originally posted by visakh16

your tables which gives you above output

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/





Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-07-16 : 10:05:52
can you please follow below guidelines and give data in this format?

http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

emmim44
Yak Posting Veteran

65 Posts

Posted - 2012-07-16 : 10:20:14
quote:
Originally posted by visakh16

can you please follow below guidelines and give data in this format?

http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/





what is missing? is the sample data?

By the way, I have updated query as follow and getting the err of "Invalid object name 'unsacountB'." :
	SELECT 	p.firstname,p.lastname, u.XProxyContext, dw.[OldValue],newVal =
(select dbc.ColumnName from unsacountB where dbc.ColumnName in
(SELECT name FROM sys.columns WHERE OBJECT_NAME(object_id) = 'unsaccountb')
)
,dwo.operationDate, dwo.OperationType,dbc.ColumnName,dbc.TableName
FROM DialogWatchProperty dw
INNER JOIN DialogWatchOperation dwo ON dw.UID_DialogWatchOperation = dwo.UID_DialogWatchOperation
INNER JOIN UNSAccountB u ON dwo.ObjectKey = u.xObjectKey
INNER JOIN Person p ON p.uid_person = u.uid_person
INNER JOIN DialogColumn dbc on dbc.UID_DialogColumn = dw.UID_DialogColumn
where ---OperationType = 'U'
dwo.operationDate between convert(varchar,@sDate,1) and convert(varchar,@eDate,1)
----And dbc.ColumnName = u1.
And u.XProxyContext = @TargetSystem
And p.FirstName = (case when @FirstName <>'' then @FirstName else p.FirstName end)
And p.LastName = (case when @LastName <>'' then @LastName else p.LastName end)
And p.CentralAccount =
(case when @userName <>'' then @userName else p.CentralAccount end)
And PersonnelNumber = (case when @personelNumber <>'' then @personelNumber else PersonnelNumber end)

order by firstname,lastname,dbc.ColumnName asc, dwo.operationDate desc
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-07-16 : 10:29:07
its a typo. table name is missing an extra c in account

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

emmim44
Yak Posting Veteran

65 Posts

Posted - 2012-07-16 : 10:54:47
quote:
Originally posted by visakh16

its a typo. table name is missing an extra c in account

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/





is the logic i update on latest query wrong or right?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-07-16 : 11:29:05
quote:
Originally posted by emmim44

quote:
Originally posted by visakh16

its a typo. table name is missing an extra c in account

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/





is the logic i update on latest query wrong or right?




We cant suggest on that unless we know what exactly you're trying to achieve.
that was purpose of asking required information as per previous link posted.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

emmim44
Yak Posting Veteran

65 Posts

Posted - 2012-07-16 : 14:59:34
quote:
Originally posted by visakh16

quote:
Originally posted by emmim44

quote:
Originally posted by visakh16

its a typo. table name is missing an extra c in account

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/





is the logic i update on latest query wrong or right?




We cant suggest on that unless we know what exactly you're trying to achieve.
that was purpose of asking required information as per previous link posted.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/





What else is missing from what I had posted here?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-07-16 : 22:20:23
how can we understand what are table data in those fields from what you posted and what you're trying to achieve from it. As suggested, please see how steps are explained in link and post relevant information. Unless you do that its really hard for someone to make out whats the issue with current query as well as your method. Unless you do that, we will keep on guessing which is both a waste of time and effort for both of us

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

emmim44
Yak Posting Veteran

65 Posts

Posted - 2012-07-17 : 04:25:20
t
Go to Top of Page
   

- Advertisement -