Author |
Topic |
tooba
Posting Yak Master
224 Posts |
Posted - 2013-02-06 : 11:38:09
|
Hi guys, I really appreciate if someone reply back ASAP.Here is my sample dataTable Name = AddPrID,NOTES1, ADD PR2, DELETE PR1, ADD PR3, ABC1, ADD Pr3,Add PrHere is the query that i am usingSelect ID, COUNT(DISTINCT ID) 'ADDPr into #temp1 from AddPrwhere notes like '%ADD PR%'GROUP BY IDi am gettingID,AddPr1,12,13,1However i wantID,AddPr1,33,1Please guide me where i am wrong. Thank You. |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-02-06 : 11:41:42
|
this is enoughSelect ID, COUNT(*) 'ADDPr into #temp1 from AddPrwhere notes like '%ADD PR%'GROUP BY ID ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
tooba
Posting Yak Master
224 Posts |
Posted - 2013-02-06 : 11:46:11
|
Awesome it will work, However i am getting other weired problem. When i am updating this result in other table using Updat statment. I am only getting * value not other value. Do you have any idea why? |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-02-06 : 11:48:27
|
hmm? can you show your full update query please? also whats the datatype of field on which you're doing the update?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
tooba
Posting Yak Master
224 Posts |
Posted - 2013-02-06 : 11:51:56
|
Here is my Simple Update StatementUPDATE #TEMP1SET #TEMP1.AddPr = P.ADDPrFROM #TempProcedure PWHERE #TEMP1.ID = P.ID |
|
|
tm
Posting Yak Master
160 Posts |
Posted - 2013-02-06 : 13:27:45
|
Try ..UPDATE TESET #TEMP1.AddPr = P.ADDPrFROM #TEMP1 TE INNER JOIN #TempProcedure PON TE.ID = P.IDtry |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-02-06 : 22:46:17
|
quote: Originally posted by tooba Here is my Simple Update StatementUPDATE #TEMP1SET #TEMP1.AddPr = P.ADDPrFROM #TempProcedure PWHERE #TEMP1.ID = P.ID
this update wont work.But I guess error you're getting is something unrelatedcan you post exact error message you got?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-02-06 : 22:46:17
|
quote: Originally posted by tooba Here is my Simple Update StatementUPDATE #TEMP1SET #TEMP1.AddPr = P.ADDPrFROM #TempProcedure PWHERE #TEMP1.ID = P.ID
this update wont work.But I guess error you're getting is something unrelatedcan you post exact error message you got?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
tooba
Posting Yak Master
224 Posts |
Posted - 2013-02-06 : 23:26:13
|
Thanks all of you guys. I solved this issue to create a @Variable Instead of #Temp Table and its working fine. Note:- It was not any error. When i use above Update statement Instead of any value it insert *. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-02-07 : 00:02:08
|
thats because of truncation error i guess. if your destination field doesnt have range to display converted value, it will show a *see below part from books online which speaks on thisTruncating and Rounding Results------------------------------------------------------When you convert character or binary expressions (char, nchar, nvarchar, varchar, binary, or varbinary) to an expression of a different data type, data can be truncated, only partially displayed, or an error is returned because the result is too short to display. Conversions to char, varchar, nchar, nvarchar, binary, and varbinary are truncated, except for the conversions shown in the following table.From data type To data type Result----------------------------------------------------------------------------------------------------------int , smallint, or tinyint char * varchar * ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
|