Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6920047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:05:53+00:00 2026-05-27T10:05:53+00:00

I have the following table: ThisCategoryID int IDENTITY, AUTO_INCREMENT Title text Type text CategoryID

  • 0

I have the following table:

ThisCategoryID int   IDENTITY, AUTO_INCREMENT
Title          text
Type           text
CategoryID     int   ALLOW NULLS
IsActive       bit
OrderIndex     int   ALLOW NULLS

with this data:

ThisCategoryID  Title    Type          CategoryID  IsActive  OrderIndex
0               Lunch    Menu Section  NULL        True      3
2               Dessert  Menu Section  NULL        True      1
3               Banh Mi  Food Item     0           True      4

and the following stored procedure:

ALTER PROCEDURE [dbo].[sp_new_category]
    @Title text,
    @Type text,
    @CategoryID int = null,
    @IsActive bit, 
    @OrderIndex int = null
AS
    DECLARE @Identity int
    IF (SELECT count(*) FROM Category WHERE difference(title, @title) = 4) > 0
    BEGIN
        INSERT INTO Category (Title, Type, CategoryID, IsActive, OrderIndex) VALUES (@Title, @Type, @CategoryID, @IsActive, @OrderIndex)
        SET @Identity = scope_identity()
    END
    ELSE
    BEGIN
        SET @Identity = -1
    END
    SELECT @Identity AS ID
    RETURN @Identity

There is no item in the table with the title “Snack”, yet the sp_new_category yields -1, every time I run it with the following parameters:

 @Title: Snack
 @Type: Menu Section
 @CategoryID: NULL
 @IsActive: True
 @OrderIndex: NULL

Can someone explain to me why that is?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T10:05:54+00:00Added an answer on May 27, 2026 at 10:05 am

    I believe your intent for the following conditional is to check if someone is trying enter an already existing item by Title (matched with SOUNDEX):

    IF (SELECT count(*) FROM Category WHERE difference(title, @title) = 4) > 0
    

    However, the way the conditional is written, you will only add items if they are similar. Try this instead:

    DECLARE @Identity int
    IF (SELECT count(*) FROM Category WHERE difference(title, @title) = 4) > 0
    BEGIN
        SET @Identity = -1
    END
    ELSE
    BEGIN
        INSERT INTO Category (Title, Type, CategoryID, IsActive, OrderIndex) VALUES (@Title, @Type, @CategoryID, @IsActive, @OrderIndex)
        SET @Identity = scope_identity()
    END
    SELECT @Identity AS ID
    RETURN @Identity
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following table in MySQL (version 5): id int(10) UNSIGNED No auto_increment
I Have the following table: CREATE TABLE `tmp_table` ( `id` int(11) NOT NULL AUTO_INCREMENT,
I have the following table in my database: CREATE TABLE [dbo].[XmlData]( [id] [int] IDENTITY(1,1)
I have the following table CREATE TABLE [dbo].[LogFiles_Warehouse]( [id] [int] IDENTITY(1,1) NOT NULL, [timestamp]
I have following table (type, id, title). When new object is created and type=1
I have the following table: CREATE TABLE `events` ( `evt_id` int(11) NOT NULL AUTO_INCREMENT,
I have the following table structures CREATE TABLE [dbo].[WorkItem]( [WorkItemId] [int] IDENTITY(1,1) NOT NULL,
I have following table. <form method=post action=test.php> <input name=id[] type=text value=ID1 /> <input name=value[]
I have the following table structure CREATE TABLE `table` ( `id` int(11) NOT NULL
I have following table alt text http://img683.imageshack.us/img683/930/town.png I want to update its TownId from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.