Re: Getting last row / auto_increment..
| From: | Michel | Date: | Mon, 03 Jul 2000 18:11:53 +0000 |
| Subject: | Re: Getting last row / auto_increment.. | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-837@lists.php.net to get a copy of this message | ||
Hello
you could use this, it's not very elegant but it works in SQLServer6.5
select nouv_val = 'xx'+
right('0000'+convert(varchar(4),max(convert(int,substring(xxyyyy,3,4)))+1),4)
from test
create table test (xxyyyy char(6) not null, ...)
where the table 'test' is the table where you store your ID xxyyyy the
'nouv_val' is the value you will insert to create a new id
I hope I've answered your question
Michel
Chad Day wrote:
> I have a database where the ID field is in the form XXYYYY, where XX is a
> couple of letters, and YYYY is a numerical value, which needs to increment
> by 1 for each entry. Since there is text being used in this field, I can't
> make it auto_increment.. what would be the best way to handle this then?
> How can I grab the last value? All I can think of is cutting off the YYYY
> using substr, then adding 1 to the YYYY value. I need to know how to get
> the last row in the table though first.. of course there might be an easier
> way too, so any advice would be appreciated :)
>
> Chad Day
> Beach Associates
>
> When I speak german... I think german in my head... but like...Do skript
> kiddies see a w40l3 8uncha 1's and 0's and 3's and 4's and 7's in
> their
> h34d'5 w43n t43y R +a1k1n6 ? -- SirStanley
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net
> For additional commands, e-mail: php-db-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net