SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Join Query Help
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

emmim44
Yak Posting Veteran

65 Posts

Posted - 07/13/2012 :  05:05:46  Show Profile  Reply with Quote
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?


Edited by - emmim44 on 07/20/2012 08:30:34

visakh16
Very Important crosS Applying yaK Herder

India
52249 Posts

Posted - 07/13/2012 :  10:32:22  Show Profile  Reply with Quote
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 - 07/13/2012 :  10:56:34  Show Profile  Reply with Quote
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


Edited by - emmim44 on 07/13/2012 16:01:42
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52249 Posts

Posted - 07/13/2012 :  23:57:31  Show Profile  Reply with Quote
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 - 07/15/2012 :  13:19:59  Show Profile  Reply with Quote
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

India
52249 Posts

Posted - 07/15/2012 :  23:28:07  Show Profile  Reply with Quote
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 - 07/16/2012 :  05:46:33  Show Profile  Reply with Quote
quote:
Originally posted by visakh16

your tables which gives you above output

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






Edited by - emmim44 on 07/20/2012 08:30:05
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52249 Posts

Posted - 07/16/2012 :  10:05:52  Show Profile  Reply with Quote
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 - 07/16/2012 :  10:20:14  Show Profile  Reply with Quote
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

India
52249 Posts

Posted - 07/16/2012 :  10:29:07  Show Profile  Reply with Quote
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 - 07/16/2012 :  10:54:47  Show Profile  Reply with Quote
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

India
52249 Posts

Posted - 07/16/2012 :  11:29:05  Show Profile  Reply with Quote
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 - 07/16/2012 :  14:59:34  Show Profile  Reply with Quote
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

India
52249 Posts

Posted - 07/16/2012 :  22:20:23  Show Profile  Reply with Quote
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 - 07/17/2012 :  04:25:20  Show Profile  Reply with Quote
t

Edited by - emmim44 on 07/20/2012 08:29:46
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.12 seconds. Powered By: Snitz Forums 2000