| Author |
Topic  |
|
|
tooba
Posting Yak Master
105 Posts |
Posted - 02/06/2013 : 11:38:09
|
Hi guys,
I really appreciate if someone reply back ASAP.
Here is my sample data
Table Name = AddPr ID,NOTES 1, ADD PR 2, DELETE PR 1, ADD PR 3, ABC 1, ADD Pr 3,Add Pr
Here is the query that i am using
Select ID, COUNT(DISTINCT ID) 'ADDPr into #temp1 from AddPr where notes like '%ADD PR%' GROUP BY ID
i am getting
ID,AddPr 1,1 2,1 3,1
However i want
ID,AddPr 1,3 3,1
Please guide me where i am wrong. Thank You.
|
|
|
visakh16
Very Important crosS Applying yaK Herder
India
47023 Posts |
Posted - 02/06/2013 : 11:41:42
|
this is enough
Select ID, COUNT(*) 'ADDPr into #temp1
from AddPr
where notes like '%ADD PR%'
GROUP BY ID
------------------------------------------------------------------------------------------------------ SQL Server MVP http://visakhm.blogspot.com/
|
 |
|
|
tooba
Posting Yak Master
105 Posts |
Posted - 02/06/2013 : 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
India
47023 Posts |
Posted - 02/06/2013 : 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 MVP http://visakhm.blogspot.com/
|
 |
|
|
tooba
Posting Yak Master
105 Posts |
Posted - 02/06/2013 : 11:51:56
|
Here is my Simple Update Statement
UPDATE #TEMP1 SET #TEMP1.AddPr = P.ADDPr FROM #TempProcedure P WHERE #TEMP1.ID = P.ID |
 |
|
|
tm
Posting Yak Master
137 Posts |
Posted - 02/06/2013 : 13:27:45
|
Try ..
UPDATE TE SET #TEMP1.AddPr = P.ADDPr FROM #TEMP1 TE INNER JOIN #TempProcedure P ON TE.ID = P.IDtry |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
India
47023 Posts |
Posted - 02/06/2013 : 22:46:17
|
quote: Originally posted by tooba
Here is my Simple Update Statement
UPDATE #TEMP1 SET #TEMP1.AddPr = P.ADDPr FROM #TempProcedure P WHERE #TEMP1.ID = P.ID
this update wont work. But I guess error you're getting is something unrelated
can you post exact error message you got?
------------------------------------------------------------------------------------------------------ SQL Server MVP http://visakhm.blogspot.com/
|
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
India
47023 Posts |
Posted - 02/06/2013 : 22:46:17
|
quote: Originally posted by tooba
Here is my Simple Update Statement
UPDATE #TEMP1 SET #TEMP1.AddPr = P.ADDPr FROM #TempProcedure P WHERE #TEMP1.ID = P.ID
this update wont work. But I guess error you're getting is something unrelated
can you post exact error message you got?
------------------------------------------------------------------------------------------------------ SQL Server MVP http://visakhm.blogspot.com/
|
 |
|
|
tooba
Posting Yak Master
105 Posts |
Posted - 02/06/2013 : 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
India
47023 Posts |
Posted - 02/07/2013 : 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 this
Truncating 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 MVP http://visakhm.blogspot.com/
|
 |
|
| |
Topic  |
|