On the other hand, because I don’t know the structure of the data table and the data in the table, based on your query, I guess you might want to do this:
Query the maximum number of user_id records and add 1 to the number of records.
If this is the case,the query should like this:
select count(user_id)+1 as [count] from tbl_dummy where id = (select max(user_id) from tbl_dummy)
Query the value of the largest user_id and add 1 to this value
If this is the case,the query should like this:
select max(user_id)+1 as user_id from tbl_dummy
Best regards,
Xudong Peng
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
Member
55 Points
191 Posts
Problem in Query?
Jun 07, 2020 09:00 AM|prabhjot1313|LINK
hello where is error in my query where userid column count userid + 1 and provide result
please execute them?
SELECT MAX(user_id) count + 1 as user_id FROM tbl_dummy
All-Star
53051 Points
23634 Posts
Re: Problem in Query?
Jun 07, 2020 11:19 AM|mgebhard|LINK
I think you are looking for the following syntax.
However, you probably should be using an IDENTITY column for user_id.
https://docs.microsoft.com/en-us/sql/t-sql/statements/create-table-transact-sql-identity-property?view=sql-server-ver15
Contributor
2110 Points
673 Posts
Re: Problem in Query?
Jun 08, 2020 07:26 AM|XuDong Peng|LINK
Hi, prabhjot1313
The main error of your query is on the count keyword, which is a sql function used to count the number of records.
So your syntax is wrong, and your query cannot be executed correctly.
More details, you could refer this document.
On the other hand, because I don’t know the structure of the data table and the data in the table, based on your query, I guess you might want to do this:
If this is the case,the query should like this:
If this is the case,the query should like this:
Best regards,
Xudong Peng