Showing posts with label generate. Show all posts
Showing posts with label generate. Show all posts

Friday, March 9, 2012

how to add autonumber (increment) unique ID to sqlserver

Hi,

I am a newbie learning sql server. I used to use Access table where I set the primary ID (int) as autonumber. Every insert will generate a new ID, which is incremented by 1.

How do I add an INSERT statement to add the incrementing primary ID in sql server. I noticed that you can't set the ID to autonumber as you do in Access. I read that you can set the ID as identity, which can auto increment.

How do I handle this in the INSERT cmd. The only thought is to call a sql cmd with a max on the current id and increment by 1 in vbscript. Afterwards, add the increment ID into the INSERT call.

Is there an easier way to do this?

Thanks,

JohnHi John,

Correct. You can't write to an identity field (and I didn't know you could in Access). You don't write to it, so don't include that field in your insert statement.

If you need the new ID number, return the value from the SQL Server SCOPE_IDENTITY function after you insert the row, either by returning it from your stored procedure or immediately after doing the insert. And you can batch them together so that you have only one round trip to the SQL Server server.

And there are lots of ways to do this, depending on the needs of your application.

Is that enough information? If not, just ask. It's pretty straightforward once you get to know SQL Server a bit.

Don

Wednesday, March 7, 2012

How to add an image dynamically using an URL

I need to generate a report which (1)using a dataset to get the path
and file names of a group of GIF images from a database table, and (2)
dynamically construct an URL for each images, and finally (3) using the
URLs to dynamically add the images into the report pages.
Since I have millions of images stored in a virtual directory, I cannot
add them all into my report project.
Thanks in advance if anybody have any solution and can share it with
me!
TommyYou will need SP1 of RS 2000 which supports retrieving "external" images
through http://. Check section 4.1.4 of the SP1 readme for details.
-- Robert
This posting is provided "AS IS" with no warranties, and confers no rights.
"Tommy" <qtao@.doe.k12.de.us> wrote in message
news:1114002588.814601.73710@.g14g2000cwa.googlegroups.com...
>I need to generate a report which (1)using a dataset to get the path
> and file names of a group of GIF images from a database table, and (2)
> dynamically construct an URL for each images, and finally (3) using the
> URLs to dynamically add the images into the report pages.
> Since I have millions of images stored in a virtual directory, I cannot
> add them all into my report project.
> Thanks in advance if anybody have any solution and can share it with
> me!
> Tommy
>

How to add a newline sequence

I have a SQL 2005 stored procedure to generate an email when passed parameters such as receipient, subject etc

One of the paramteres passed to it is @.body which is the body text of the message. I want to be able to add a couple of blank lines and then some footer information. This is working right now except I can't find the right way to add newlines into the string within the store procedure, so my footer information just tags right on after the bodytext.

I have tried \n but that literally adds the two characters \ and n

Can anyone advise how to generate newlien sequences in T-SQL.

Regards

Clive

Use the CHAR function e.g. CHAR(13) + CHAR(10)

Seehttp://doc.ddart.net/mssql/sql70/ca-co_4.htm