How to do zero padding ?

I have a table like this (select sym,price from hlytb):sym price------------837 9.22600461 7.74600129 7.36423 6.68and I want the sym to be zero padded to 6 digits like this :sym price------------000837 9.22600461 7.74600129 7.36000423 6.68How to do ?And this “a: `837; (count string a)_“000000”,string a” works , but"select ((count string sym)_“000000”,string sym) by sym from hlytb"not work as I want , why ?Thanks,

This should work for the padding

q)select “0”^-6$string sym,price from hlytb

sym ? ? ?price


“000837” 9.22

“600461” 7.74

“600129” 7.36

“000423” 6.68

Haven’t looked at your other question but it looks like you’re applying an atomic operation to a list (column) so you’d need an “each” in there somewhere.

Terry

thanks,the other question is when I try “select ((count stringsym)_“000000”,string sym) by sym from hlytb” , it shows:sym | sym------| ----------------------------423 | “0” “0” “0” “0” “0” "423"600062| “0” “0” “0” “0” “0” "600062"600129| “0” “0” “0” “0” “0” "600129"837 | “0” “0” “0” “0” “0” “837"and I try “select count string sym by sym from hlytb” , it showssym | sym------| —423 | 1600062| 1600129| 1837 | 1but what I want is:sym | sym------| —423 | 3600062| 6600129| 6837 | 3don’t know why the “count” can’t calculate the character number of"string sym” .On 6??14??, ???6?15??, Terry Lynch <tlync…> wrote:> This should work for the padding>> q)select “0”^-6$string sym,price from hlytb> sym price> --------------> “000837” 9.22> “600461” 7.74> “600129” 7.36> “000423” 6.68>> Haven’t looked at your other question but it looks like you’re applying an> atomic operation to a list (column) so you’d need an “each” in there> somewhere.>> Terry>>>> On Thu, Jun 14, 2012 at 11:07 AM, bigbug <matlab…> wrote:> > I have a table like this (select sym,price from hlytb):>> > sym price> > ------------> > 837 9.22> > 600461 7.74> > 600129 7.36> > 423 6.68>> > and I want the sym to be zero padded to 6 digits like this :>> > sym price> > ------------> > 000837 9.22> > 600461 7.74> > 600129 7.36> > 000423 6.68>> > How to do ?>> > And this “a: `837; (count string a)“000000”,string a" works , but> > "select ((count string sym)“000000”,string sym) by sym from hlytb”> > not work as I want , why ?>> > Thanks,>> > –> >

Submitted via Google Groups</matlab…></tlync…>

If you want to do it that way you’ll have to either modify the operation to apply to lists of strings (rather than a single string) or else apply the operation to each string. For example

q)select {(count string x)_“000000”,string x} each sym by sym from hlytb

sym   | sym

------| --------

423   | “000423”

837   | “000837”

600129| “600129”

600461| “600461”

Again, for the counting you need to apply it to each of the strings, otherwise its just counting the whole list (column) as one

 q)select count each string sym by sym from hlytb
sym   | sym

------| —

423   | 3

837   | 3

600129| 6

600461| 6

Terry

broaden my understanding of q , many thanks…On 6??14??, ???6?42??, Terry Lynch <tlync…> wrote:> If you want to do it that way you’ll have to either modify the operation to> apply to lists of strings (rather than a single string) or else apply the> operation to each string. For example>> q)select {(count string x)“000000”,string x} each sym by sym from hlytb> sym | sym> ------| --------> 423 | “000423”> 837 | “000837”> 600129| “600129”> 600461| “600461”>> Again, for the counting you need to apply it to each of the strings,> otherwise its just counting the whole list (column) as one>> q)select count each string sym by sym from hlytb> sym | sym> ------| —> 423 | 3> 837 | 3> 600129| 6> 600461| 6>> Terry>>>> On Thu, Jun 14, 2012 at 11:30 AM, bigbug <matlab…> wrote:> > thanks,>> > the other question is when I try "select ((count string> > sym)“000000”,string sym) by sym from hlytb" , it shows:>> > sym | sym> > ------| ----------------------------> > 423 | “0” “0” “0” “0” “0” “423”> > 600062| “0” “0” “0” “0” “0” “600062”> > 600129| “0” “0” “0” “0” “0” “600129”> > 837 | “0” “0” “0” “0” “0” “837”>> > and I try “select count string sym by sym from hlytb” , it shows>> > sym | sym> > ------| —> > 423 | 1> > 600062| 1> > 600129| 1> > 837 | 1>> > but what I want is:>> > sym | sym> > ------| —> > 423 | 3> > 600062| 6> > 600129| 6> > 837 | 3>> > don’t know why the “count” can’t calculate the character number of> > “string sym” .>> > On 6??14??, ???6?15??, Terry Lynch <tlync…> wrote:> > > This should work for the padding>> > > q)select “0”^-6$string sym,price from hlytb> > > sym price> > > --------------> > > “000837” 9.22> > > “600461” 7.74> > > “600129” 7.36> > > “000423” 6.68>> > > Haven’t looked at your other question but it looks like you’re applying> > an> > > atomic operation to a list (column) so you’d need an “each” in there> > > somewhere.>> > > Terry>> > > On Thu, Jun 14, 2012 at 11:07 AM, bigbug <matlab…> wrote:> > > > I have a table like this (select sym,price from hlytb):>> > > > sym price> > > > ------------> > > > 837 9.22> > > > 600461 7.74> > > > 600129 7.36> > > > 423 6.68>> > > > and I want the sym to be zero padded to 6 digits like this :>> > > > sym price> > > > ------------> > > > 000837 9.22> > > > 600461 7.74> > > > 600129 7.36> > > > 000423 6.68>> > > > How to do ?>> > > > And this “a: `837; (count string a)“000000”,string a" works , but> > > > "select ((count string sym)“000000”,string sym) by sym from hlytb”> > > > not work as I want , why ?>> > > > Thanks,>> > > > –> > > > You received this message because you are subscribed to the Google> > Groups> > > > “Kdb+ Personal Developers” group.> > > > To post to this group, send email to personal-kdbplus@googlegroups.com> > .> > > > To unsubscribe from this group, send email to> > > > personal-kdbplus+unsubscribe@googlegroups.com.> > > > For more options, visit this group at> > > >http://groups.google.com/group/personal-kdbplus?hl=en.-??? ->> > > - ???õ??? ->> > –> >

Submitted via Google Groups</matlab…></tlync…></matlab…></tlync…>

You can try floowing…

 

q)select sym, count each string sym from hlytb

sym         sym1

837             3
423             3
600129        6
600461        6
60046178    8

Thanks

Hemant