Hello. I have a table that has 3 fields as a primary key - JobID (int),
PONumber (char 16) and PORevision (tinyint). I need to make a new row with
the same data except the PORevision field should be increased by 1. I have
tried a few things but nothing seems to work. I could do it in my vb.net
code but I am sure it would be better in the sql database.
Thanks,
Gerry
INSERT INTO YourTable (jobid, ponumber, porevision, other_col, ...)
SELECT jobid, ponumber, porevision+1, other_col, ...
FROM YourTable
WHERE ...
David Portas
SQL Server MVP
Showing posts with label char. Show all posts
Showing posts with label char. Show all posts
Saturday, February 25, 2012
Copy a row with one change?
Hello. I have a table that has 3 fields as a primary key - JobID (int),
PONumber (char 16) and PORevision (tinyint). I need to make a new row with
the same data except the PORevision field should be increased by 1. I have
tried a few things but nothing seems to work. I could do it in my vb.net
code but I am sure it would be better in the sql database.
Thanks,
GerryINSERT INTO YourTable (jobid, ponumber, porevision, other_col, ...)
SELECT jobid, ponumber, porevision+1, other_col, ...
FROM YourTable
WHERE ...
David Portas
SQL Server MVP
--
PONumber (char 16) and PORevision (tinyint). I need to make a new row with
the same data except the PORevision field should be increased by 1. I have
tried a few things but nothing seems to work. I could do it in my vb.net
code but I am sure it would be better in the sql database.
Thanks,
GerryINSERT INTO YourTable (jobid, ponumber, porevision, other_col, ...)
SELECT jobid, ponumber, porevision+1, other_col, ...
FROM YourTable
WHERE ...
David Portas
SQL Server MVP
--
Copy a row with one change?
Hello. I have a table that has 3 fields as a primary key - JobID (int),
PONumber (char 16) and PORevision (tinyint). I need to make a new row with
the same data except the PORevision field should be increased by 1. I have
tried a few things but nothing seems to work. I could do it in my vb.net
code but I am sure it would be better in the sql database.
Thanks,
GerryINSERT INTO YourTable (jobid, ponumber, porevision, other_col, ...)
SELECT jobid, ponumber, porevision+1, other_col, ...
FROM YourTable
WHERE ...
--
David Portas
SQL Server MVP
--|||Or you could make the PORevision field an identity and
the system would do it for you.
>--Original Message--
>Hello. I have a table that has 3 fields as a primary
key - JobID (int),
>PONumber (char 16) and PORevision (tinyint). I need to
make a new row with
>the same data except the PORevision field should be
increased by 1. I have
>tried a few things but nothing seems to work. I could
do it in my vb.net
>code but I am sure it would be better in the sql
database.
>Thanks,
>Gerry
>
>.
>
PONumber (char 16) and PORevision (tinyint). I need to make a new row with
the same data except the PORevision field should be increased by 1. I have
tried a few things but nothing seems to work. I could do it in my vb.net
code but I am sure it would be better in the sql database.
Thanks,
GerryINSERT INTO YourTable (jobid, ponumber, porevision, other_col, ...)
SELECT jobid, ponumber, porevision+1, other_col, ...
FROM YourTable
WHERE ...
--
David Portas
SQL Server MVP
--|||Or you could make the PORevision field an identity and
the system would do it for you.
>--Original Message--
>Hello. I have a table that has 3 fields as a primary
key - JobID (int),
>PONumber (char 16) and PORevision (tinyint). I need to
make a new row with
>the same data except the PORevision field should be
increased by 1. I have
>tried a few things but nothing seems to work. I could
do it in my vb.net
>code but I am sure it would be better in the sql
database.
>Thanks,
>Gerry
>
>.
>
Friday, February 10, 2012
converting newId()
Hi there!
Is there any way to convert generated newId() hexa into an int ?
for example, the first two char into an int which won't be greater
than 255
I've searched for 'convert' or 'cast' but i found nothing...
any idea?
thanks a lot
Vince.Why not just use RAND() ?
Please post DDL, sample data and desired results.
See http://www.aspfaq.com/5006 for info.
"Vince .>" <vincent@.<remove> wrote in message
news:qfp541pgb9rfon1nk7cblubersvl3ki0cc@.
4ax.com...
> Hi there!
> Is there any way to convert generated newId() hexa into an int ?
> for example, the first two char into an int which won't be greater
> than 255
> I've searched for 'convert' or 'cast' but i found nothing...
> any idea?
> thanks a lot
> Vince.|||If you just want to convert newid() to int, try:
select convert(int, convert(varbinary, newid()))
"Vince .>" wrote:
> Hi there!
> Is there any way to convert generated newId() hexa into an int ?
> for example, the first two char into an int which won't be greater
> than 255
> I've searched for 'convert' or 'cast' but i found nothing...
> any idea?
> thanks a lot
> Vince.
>
Is there any way to convert generated newId() hexa into an int ?
for example, the first two char into an int which won't be greater
than 255
I've searched for 'convert' or 'cast' but i found nothing...
any idea?
thanks a lot
Vince.Why not just use RAND() ?
Please post DDL, sample data and desired results.
See http://www.aspfaq.com/5006 for info.
"Vince .>" <vincent@.<remove> wrote in message
news:qfp541pgb9rfon1nk7cblubersvl3ki0cc@.
4ax.com...
> Hi there!
> Is there any way to convert generated newId() hexa into an int ?
> for example, the first two char into an int which won't be greater
> than 255
> I've searched for 'convert' or 'cast' but i found nothing...
> any idea?
> thanks a lot
> Vince.|||If you just want to convert newid() to int, try:
select convert(int, convert(varbinary, newid()))
"Vince .>" wrote:
> Hi there!
> Is there any way to convert generated newId() hexa into an int ?
> for example, the first two char into an int which won't be greater
> than 255
> I've searched for 'convert' or 'cast' but i found nothing...
> any idea?
> thanks a lot
> Vince.
>
Subscribe to:
Posts (Atom)