You do know your stored procedure has an implicit race condition, don't you?
Between your calculating the new query id and your table insert getting committed, another session can come in, get exactly the same query id, insert it and get committed. Guess what happens when your insert tries to commit? First in wins; the second gets a duplicate key error. Don't ask me how I know this :)
If you really need a text query id, you might try using a computed field, something like this:
create table dbo.tblCatQuery
(
query_id int not null identity(1,1) primary key clustered ,
query_id_text as right('0000000000'+convert(varchar,id),10) ,
user_id varchar(20) not null ,
cat_id varchar(20) not null ,
query varchar(100) not null ,
query_title varchar(50) not null ,
)
Then your stored procedure looks like this:
create procedure dbo.spInsertCatQuery
@Users_Id varchar(20) ,
@Cat_Id varchar(20) ,
@Query varchar(100) ,
@Query_Title varchar(50) ,
@Query_ID varchar(10) output
AS
insert dbo.tblCatQuery ( user_id , cat_id , query_title , query )
VALUES ( @Users_Id , @Cat_Id , @Query_Title , @Query )
-- give the caller back the id of the row just inserted
set @Query_ID = @@SCOPE_IDENTITY
-- for redundancy, hand it back as the SP's return code, too
return @Query_ID
GO