-1

Please help me to do this. Generate an id from database but id should start from one on each new date. Using c# and SQL server.

Waseem
  • 23
  • 1
  • 3
  • [This link](https://www.google.com) will get you started. – Guy Jun 07 '17 at 05:57
  • Welcome to Stack Overflow. Your question will probably be closed soon because it is overly broad and non-specific, but don't let that deter you from seeking help. Please see how to ask a question https://stackoverflow.com/help/how-to-ask, and improve your question. – STLDev Jun 07 '17 at 06:07
  • See my answer hopefully that will work – Gulam Husain Ansari Jun 07 '17 at 07:16

1 Answers1

0

Please modify below SQL procedure based on your requirement

create proc [dbo].[InsertRecord]
    as
    begin
        declare @ID int=0;
        if (select count(1) from table_1 where CONVERT(VARCHAR(10),CurrentDate,10)=CONVERT(VARCHAR(10),GETDATE(),10))=0
            begin
                set @ID=1;
            end
        else 
            begin
                set @ID=(select top 1 ID from table_1 order by CurrentDate desc);
                set @ID=isnull(@ID,0)+1;
            end

        insert into table_1(ID,CurrentDate)values(@ID,GETDATE());
        select * from table_1;
    end