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.
| Author |
Topic |
|
Sarakumar
Posting Yak Master
108 Posts |
Posted - 2009-04-17 : 04:14:31
|
| Hai, can we use join with the udf.meaning, can i join my table result with udf result.if so, how..1. how can i sum the char column valuesay, producttableitemcode = '12345'(varchar20)how can i sum the column. i want to sum each column. |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-04-17 : 04:58:35
|
| select sum(char_col*1) from your_tableExplain how you want to join with result of udfMadhivananFailing to plan is Planning to fail |
 |
|
|
Sarakumar
Posting Yak Master
108 Posts |
Posted - 2009-04-17 : 05:57:58
|
| declare @product table(id int,model varchar(10))insert into @product values (1,'11111')insert into @product values(2,'11112')insert into @product values (3,'11113')select * from @productselect sum(model*1) from @producthai i want the output as 1 52 63 7how to get it |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-04-17 : 10:23:03
|
| [code]CREATE FUNCTION AddDigits (@StrVal varchar(20))RETURNS intASDECLARE @Sum int,@Digit intWHILE @StrVal >''BEGINSELECT @Digit=LEFT(@StrVal,1), @StrVal = SUBSTRING(@StrVal,2,LEN(@StrVal))SET @Sum=COALESCE(@Sum,0)+@DigitENDRETURN @SumENDthen use udf like thisSELECT id,dbo.AddDigits(model)FROM @product[/code] |
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-04-18 : 00:12:13
|
| [code]try this one toodeclare @product table(id int,model varchar(10))insert into @product values (1,'11111')insert into @product values(2,'11112')insert into @product values (3,'11113')insert into @product values (4,'11117')select id,sum(cast(substring(model,number,1) as int))from @product pinner join master..spt_values as m on m.type = 'p'where len(model) >= numbergroup by id[/code] |
 |
|
|
|
|
|
|
|