logo
down
shadow

How could I generate auto insert function SEAT_NO like A1,A2.... B1,B2 in sql server


How could I generate auto insert function SEAT_NO like A1,A2.... B1,B2 in sql server

By : Warren Adams-Ockrass
Date : November 20 2020, 01:01 AM
Hope that helps I would re-write the whole function and scrap all of this string manipulation, See below:
Function Definition
code :
Create function Fun_Auto_Insert()
returns nchar(3)
as
BEGIN 
    DECLARE @Seat_No NCHAR(3);

;WITH CTE AS 
(SELECT Alphas+vals AS SEAT_NO
      ,Alphas 
      ,vals  
FROM (
    select CHAR(number) Alphas
    from master..spt_values
    WHERE number >= 65 and number <= 90
    GROUP BY number) A
              CROSS APPLY (VALUES ('1'),('2'),('3'),('4')
                                 ,('5'),('6'),('7'),('8')
                                 ,('9'),('10'),('11'),('12'))C(vals)
)
SELECT TOP 1 @Seat_No = SEAT_NO
FROM CTE C
WHERE NOT EXISTS (SELECT 1 
                  FROM MOVIE_TICKETS
                  WHERE C.SEAT_NO = Seat_No)
ORDER BY  Alphas ASC , CAST(vals AS INT) ASC

   RETURN @Seat_No; 
END 
GO
CREATE TABLE MOVIE_TICKETS(Seat_No VARCHAR(3))
GO
INSERT INTO MOVIE_TICKETS VALUES ('A2'), ('A10'), ('B2')
GO

SELECT dbo.Fun_Auto_Insert()
GO
A1


Share : facebook icon twitter icon
Auto generate key on JDBC insert in SQL Server

Auto generate key on JDBC insert in SQL Server


By : Oleg S.
Date : March 29 2020, 07:55 AM
it should still fix some issue This is completely database dependent. There are two main options: 1 - DBMSs that allow an auto-increment keyword next to the primary key definition and 2 - DBMSs that provide sequence generators (that you then can use to generate the new values for the PK, for instance by writing a "before insert" trigger that automatically inserts the new value in the column before completing the insertion ).
As far as I know:
What is the best way to auto-generate INSERT statements for a SQL Server table?

What is the best way to auto-generate INSERT statements for a SQL Server table?


By : Christopher Brack
Date : March 29 2020, 07:55 AM
hop of those help? Microsoft should advertise this functionality of SSMS 2008. The feature you are looking for is built into the Generate Script utility, but the functionality is turned off by default and must be enabled when scripting a table.
This is a quick run through to generate the INSERT statements for all of the data in your table, using no scripts or add-ins to SQL Management Studio 2008:
Auto generate function in SQL Server 2000

Auto generate function in SQL Server 2000


By : meso
Date : March 29 2020, 07:55 AM
will help you You could just use a normal auto incrementing identity column and the following formula (possibly in a derived column) to map this to display format.
code :
CHAR((id-1)/9999/999 + 65) + 
RIGHT('0000' + CAST(1 + (id-1)%(999*9999)/999 AS VARCHAR(4)),4) + 
'-' + 
RIGHT('000' + CAST(1 + (id-1)%999 AS VARCHAR(3)),3)
Issues with getting uniqueidentifier auto generate in SQL on insert

Issues with getting uniqueidentifier auto generate in SQL on insert


By : user2884589
Date : March 29 2020, 07:55 AM
Hope this helps I am trying to insert data from one table into another table. Table1 doesn't have a uniqueidentifier, but Table2 does. I have tried to insert using NEWID(), but I get a syntax error. Can someone please tell me what I am doing wrong? , In case Table2 is not yet created you can use this query:
code :
SELECT
     NEWID() AS [ID]
    ,Description AS [Item Description]
    ,Cost AS [Item Cost]
INTO Table2
FROM Table1
WHERE Id = '1'
INSERT INTO Table2 ([ID], [Item Description], [Item Cost])
SELECT
   NEWID()
   , Description
   , Cost
FROM Table1
WHERE Id = '1'
CREATE TABLE Table2 (
    [ID] INT Identity
    ,[Item Description] AS NVARCHAR(MAX)
    ,[Item Cost] AS NUMERIC(18, 2))

INSERT INTO Table2([Item Description] , [Item Cost])
SELECT
    Description
    , Cost
FROM Table1
WHERE Id = '1'
How to auto generate UniqueIdentifier on insert query in Sql Server?

How to auto generate UniqueIdentifier on insert query in Sql Server?


By : Priyanka Hallubai
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , When you create a table, you can create a column with uniqueidentifier data type as you did and with the default DEFAULT newid() as below
code :
CREATE TABLE AUDITS
(
Audit_ID uniqueidentifier not null DEFAULT newid(),
LocationID char(10) FOREIGN KEY REFERENCES LOCATIONS (LocationID) not null,
DateChangement date not null,
NomColonneChang├ę varchar (20) not null,
AncienneValeur  varchar (20)  not null,
NouvelleValeur  varchar (20) not null,
constraint pk_AUDIT primary key(Audit_ID)
)
Related Posts Related Posts :
  • SQL - how to group transactions for a certain date pattern?
  • How to Index SQL with multiple AND conditions nested inside OR
  • SQL rank with priority
  • Does BigQuery support SubQueries?
  • Any ideas for persisting H2 Database In-Memory mode transaction?
  • How to improve SQL query performance (correlated subqueries)?
  • Filter repeated columns in Oracle
  • SQL Server join on whichever column has value populated
  • use sql stored procedure to insert data which is returned from a query stored in a table
  • Query not working1
  • SQL - using an alias in a where clause in a subquery
  • How to search for a whole word with special char using oracle contains?
  • Production Perfomance of using SELECT * statements?
  • String concatenation not working as expected in SELECT statement
  • How to detect which stored procedures UPDATE or INSERT into a certain TABLE?
  • Select statement inside CASE - SQL
  • .Net Float error 4 - float(4) = 4.44089209850063E-16
  • How to show as column to recursive rows in a table With SQL Server
  • SQL Server error: Column name or number of supplied values does not match table definition
  • How to find a table name which's column name consist cl_
  • Cannot access existing table from WCF Code
  • SQL CREATE VIEW Error
  • Many Statement in the same transaction PLSQL
  • Tables are not joining properly in sql server 2008
  • DB2 how to sum two column from two different table
  • SQL msAccess: list unfinished courses of a student
  • SQL Server delete multiple rows
  • Finding max(date) from the resultant query output
  • updating multiple columns using case statement in sql server
  • Nested SQL query having select subquery in update statement
  • "putting" a certain object to the screen from inside an array
  • Retrieve segment from value
  • Error while creating a table in oracle 11g
  • Transaction with Sequelize doesn't work
  • Search time complexity of this sql query
  • How to return unique records between two tables without using distinct and union?
  • Is it possible to maximum occurences of a value for each key in my table all in one query?
  • Divide table into groups of 5000 based on rank
  • rolling back exec and sp_OA methods
  • How to convert multiple rows to one row in SQL Server?
  • How to use substring and charindex in google query language
  • Find table information where part of column matches char variable
  • Need to retrieve rows from table where the following condition was not satisfied column A = column B and column B = colu
  • Assigning an index to a constraint
  • Retrieve records from multiple Records returned by Sub-Query
  • SQL DELETE group of records based on opposite group being empty
  • SQL GetDate() returns wrong time
  • Total sales amount for customers in cities
  • SQL Server -- updating the `sys.*` tables and not just reading them
  • SQL Order By using concat
  • SQL server 2008 - subquery returned more than one value
  • Group Data Hourly and Insert Into a Summary Table in Postgres
  • Execute SQL Server Pass-Through Query From Access VBA
  • MS Access SQL Transform Aggregate Manipluation of Values for Pivot
  • SQL "if exists..." dynamic query
  • HANA: Split string?
  • Create a list of dates and match records to the list
  • Why won't SQL round correctly from my batch script?
  • SQLServer - Multiple PIVOT on same columns
  • Update a table foreign keys by substituting by a lookup from the result of another table
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org