| |
Welcome to the dBforums forums.
You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!
If you have any problems with the registration process or your account login, please contact contact support.
If you prefer not to see double-underlined words and corresponding ads, place your cursor here for ContentLink opt out.
|
 |

06-25-08, 05:56
|
|
Registered User
|
|
Join Date: Jun 2008
Location: India
Posts: 58
|
|
|
IDENTITY problem
|
Hi Guys,
When i executed the below query,
select 'N' = IDENTITY(5),name
into #sp
from sysobjects
where type = 'P'
I go the below error message.
Server Message: Number 156, Severity 15
Server 'DEV', Line 1:
Incorrect syntax near the keyword 'IDENTITY'.
what is the problem in my query ?
Inputs are welcome !
|
|

06-25-08, 06:15
|
|
Registered User
|
|
Join Date: Jun 2007
Location: London
Posts: 944
|
|
What on earth are you trying to do??? What were you hoping to do with the identity(5) bit of your SQL? If you just want the names of all the stored procedures then just do the following:
Code:
select 'N' = name
into #sp
from sysobjects
where type = 'P'
Most people rename fields to make them more readable but calling the procedure name ‘N’ certainly goes against this trend.
Mike
|
|

06-25-08, 07:45
|
|
Registered User
|
|
Join Date: Jun 2008
Location: India
Posts: 58
|
|
|
No.
My requirement is, i want to create sequential number along with the procedure name.
say for example,
1 p1
2 p2
3 p3
4 p4
.
.
.
520 p_close
|
|

06-25-08, 10:19
|
|
Who? Me?
|
|
Join Date: Jan 2004
Location: The Hague/Utrecht, NL
Posts: 273
|
|
You should create the temptable first, with the identitycolumn. Then,you insert the rows you select from sysobjects:
Code:
create procedure proc_name
as
begin
create table #sp (
sp_id numeric(5) identity,
name varchar(20)
)
go
insert into #sp (name)
select name from sysobjects
end
Something like this
__________________
I'm not crazy, I'm an aeroplane!
|
|

06-25-08, 11:02
|
|
Registered User
|
|
Join Date: Jun 2007
Location: London
Posts: 944
|
|
I agree with Martijnv's method but I'm not sure about the stored proc - won't the temporary table disappear once the proc finishes? We also seem to have missed the restriction to just stored procs. Wouldn't it be better just to leave it at :
Code:
create table #sp (
sp_id numeric(5) identity,
name varchar(20)
)
go
insert into #sp (name)
select name from sysobjects
where type='P'
select * from #sp
go
|
|

06-25-08, 11:37
|
|
Registered User
|
|
Join Date: May 2005
Location: South Africa
Posts: 830
|
|
remove the quotes around N
Code:
select N = IDENTITY(5),name
into #sp
from sysobjects
where type = 'P'
|
|

06-27-08, 05:00
|
|
Who? Me?
|
|
Join Date: Jan 2004
Location: The Hague/Utrecht, NL
Posts: 273
|
|
Quote:
|
Originally Posted by mike_bike_kite
I agree with Martijnv's method but I'm not sure about the stored proc - won't the temporary table disappear once the proc finishes? We also seem to have missed the restriction to just stored procs. Wouldn't it be better just to leave it at :
Code:
create table #sp (
sp_id numeric(5) identity,
name varchar(20)
)
go
insert into #sp (name)
select name from sysobjects
where type='P'
select * from #sp
go
|
I can imagine the temptable vanishing when the proc ends, but that doesn't have to be a problem, depending on what you want to do with the contents.
__________________
I'm not crazy, I'm an aeroplane!
|
|

06-27-08, 05:52
|
|
Registered User
|
|
Join Date: Jun 2007
Location: London
Posts: 944
|
|
It was pdreyer's solution that really threw me - it looked like it would just raise a syntax error but worked fine. Does it mean that the identity(5) is a function rather than a declaration? I tried different variations on this to try and understand what it was doing: - remove the into #sp and it fails
- remove N= it fails
- add quotes to the N with "N"= and it fails
- add quotes to other var ie "fred"=name and it's fine
Can someone explain this for me?
Mike
|
|

06-27-08, 06:12
|
|
Registered User
|
|
Join Date: Jun 2008
Location: India
Posts: 58
|
|
IDENTITY(5) mean the length of the number should be within 5. Am i correct ?
|
|

06-27-08, 06:47
|
|
Registered User
|
|
Join Date: Jun 2007
Location: London
Posts: 944
|
|
Yes you are correct but the initial question is a little deeper than that  The integer(5) would normally be a declaration of type but you couldn't change the SQL to use other types such as int:
Code:
select N = int,name
into #sp
from sysobjects
where type = 'P'
As this would generate an error rather than make N to be an integer with a null value. You could alter the SQL to use a function such as rand and it would work fine:
Code:
select N = rand(),name
into #sp
from sysobjects
where type = 'P'
Hence my first question - Does it mean that the identity(5) is a function rather than a declaration.
|
|

06-27-08, 09:34
|
|
Registered User
|
|
Join Date: May 2005
Location: South Africa
Posts: 830
|
|
identity(5) tell ASE how to define column N
Code:
select N=identity(9),name into #t1 from sysobjects where type='P'
use tempdb
go
exec sp_help #t1
drop table #t1
Name Owner Object_type
---- ----- -----------
#t1__________00002840012654325 dbo user table
Data_located_on_segment When_created
----------------------- ------------
default Jun 27 2008 2:19PM
Column_name Type Length Prec Scale Nulls Default_name Rule_name Access_Rule_name Identity
----------- ---- ----------- ----------- ----------- ----------- ------------ --------- ---------------- -----------
N numeric 5 9 0 0 NULL NULL NULL 1
name sysname 30 NULL NULL 0 NULL NULL NULL 0
exp_row_size reservepagegap fillfactor max_rows_per_page identity_gap
------------ -------------- ----------- ----------------- ------------
0 0 0 0 0
concurrency_opt_threshold optimistic_index_lock dealloc_first_txtpg
------------------------- --------------------- -------------------
15 0 0
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|