Click here to Skip to main content
15,890,947 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Table column name with Value is as below:
Log_ID is foreign key not primary key
Log_ID .....Start_Date .....End_Date .....Deposit_Sum .....Payment_Frequency
7.............2014-11-12 ....2015-11-12 ..........2131 ...........................Yearly
8............2014-11-12......2016-11-12............10000 ........................Yearly
7.............2014-11-12......2019-11-12...........50000....... .......................Yearly
9.............2014-12-12......2019-12-12...........100000 ........... ............Half Yearly

I am only able to retrieve single row for Log_ID = 7
But
How can I retrieve both row record which has got id= 7?
Posted
Updated 12-Dec-14 0:04am
v4
Comments
Wombaticus 12-Dec-14 5:45am    
Try reading what you have written as a stranger would (i.e. anyone else here) and ask yourself: what can we possibly say about it, or help you with?
Praveen Kumar Upadhyay 12-Dec-14 5:49am    
Is this your table data which you have mentioned? what data you want to display?
Gautam Thapa Magar 12-Dec-14 5:57am    
yes, Log_ID,Start_Date.End_Date,Deposit_Sum and Payment_Frequency are column name.
And I want to display all record of row which has got Log_ID = 7
Praveen Kumar Upadhyay 12-Dec-14 6:05am    
where do u want to display this record? do you want query?
Gautam Thapa Magar 12-Dec-14 6:08am    
I want to display at webform and I want query as well to correct my query

I don't know what control you are using? but,based on my observation if you use sql server as database,then your query may be like this,
C#
select Log_ID,Start_Date,End_Date,Deposit_Sum,Payment_Frequency from YourTableName where Log_ID=7

Just bind this to your control.Hope it may helpful for you.
 
Share this answer
 
v2
Comments
Praveen Kumar Upadhyay 12-Dec-14 6:20am    
This is very simple thing and anybody can answer this. the OP is very new and he does not know anything.
Rajesh waran 12-Dec-14 6:28am    
I read all comments.But i don't know about his control.Also he need query, So that i posted query. He's not clear with his question.
SQL
DECLARE @cols NVARCHAR(MAX)

SELECT  @cols = STUFF(( SELECT DISTINCT + ',' + MyData FROM    (
SELECT  +'Start: ' + Convert(Nvarchar,[StartDate],121) + ' End: ' +  Convert(Nvarchar,[EndDate],121)
+' Deposit: ' + cast([Deposit_Sum] as Nvarchar) + ' Mode: ' + [Payment_Frequency] as [MyData]
FROM [TestDB].[dbo].[TblTempLog] where log_id = 7
)a 
ORDER BY ',' + MyData
FOR XML PATH('')
), 1, 2, '') + ''

select  @cols

The Result gives you comma separated all valued in one column.
 
Share this answer
 
Comments
Rajesh waran 12-Dec-14 7:39am    
Dude! may i know why you are using stuff() here? OP didn't mention that he want comma seperated output.
Mr. Mahesh Patel 12-Dec-14 7:43am    
let me know that my answer is useful to questioner...?
And he also didn't mentioned that don't use stuff.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900