Create Column in SQL Server

Hi all,
     I am having below table.
create table Student_Register
Name varchar(30),
FatherName varchar(35),
Address1 varchar(100),
Address2 varchar(100),
Place varchar(75),
Pincode int,
SchoolName varchar(100),
StandardStudy varchar(15)
I am creating after trigger on the above table and inserting into the below table.
create table StudentDetails
Name varchar(30),
FatherName varchar(35),
Address1 varchar(100),
Address2 varchar(100),
Place varchar(75),
Pincode int,
SchoolName varchar(100),
StandardStudy varchar(15)
I need to create one computed column in studentdetails as StudentID with StandardStudy+Replicate(0,3)+lastvalue+1
5th student id
50001
50002
 12th student like
120001
120002
120003
how to implement above logic pls ?
Thanks
Selvaons
Thanks - SelvaKumarSubramaniam.Please MARK AS ANSWER, if my answer is useful to U.

see
http://www.sqlteam.com/article/custom-auto-generated-sequences-with-sql-server
You can make it computed column based on UDF
make UDF as below
CREATE FUNCTION GenerateStudID
@StdStudy varchar(15)
RETURNS int
AS
BEGIN
DECLARE @StudID int
SELECT @StudID = @StdStudy * 10000 + COALESCE((SELECT MAX(StudentID) FROM StudentDetails WHERE StandardStudy =@StdStudy),0) + 1
RETURN (@StudID)
END
then create column as
ALTER TABLE StudentDetails ADD StudentID AS dbo.GenerateStudID(StandardStudy)
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

Similar Messages

  • What is Oracle's alternative to IDENTITY Column in SQL Server/ DB2

    What is Oracle's alternative to IDENTITY Column(Auto Increment Column) in SQL Server/ DB2 ? Is Sequence and Trigger the only way out for this?
    Why is Oracle not creating anything like an Identitiy column in SQL Server?

    What is Oracle's alternative to IDENTITY Column(Auto
    Increment Column) in SQL Server/ DB2 ? Is Sequence
    and Trigger the only way out for this?Of course not, you can use in your inserts sequences as well:
    insert into blahh values (my_seq.nextval, ...) and use returniong clause to get the value back if necessary
    You can use them in insert with subselects
    insert into blah
    select my_seq.nextval, ...
    from ....
    >
    Why is Oracle not creating anything like an Identitiy
    column in SQL Server?Because they are different companies with different people and thoughts and existing mechanism is sufficient i.e. one can even argue that it is even more flexible than identity btw ;)
    Gints Plivna
    http://www.gplivna.eu

  • How to convert rows to columns in sql server 2008

    How to convert rows to columns in sql server 2008 using the GROUP BY function? (only one query allowed)

    Lookup the Pivot transformation. From BOL:
    The Pivot transformation makes a normalized data set into a less normalized
    but more compact version by pivoting the input data on a column value. For
    example, a normalized Orders data set that lists customer name, product, and quantity purchased typically has multiple rows for any customer who purchased multiple products, with each row for that customer showing order
    details for a different product. By pivoting the data set on the product column, the Pivot transformation can output a data set with a
    single row per customer. That single row lists all the purchases by the customer, with the product names shown as column names, and the quantity shown as a value in the product column. Because not every customer purchases every product, many columns may contain
    null values.
    When a dataset is pivoted, input columns perform different roles in the pivoting process. A column can participate in the following ways:
    The column is passed through unchanged to the output. Because many input rows
    can result only in one output row, the transformation copies only the first
    input value for the column.
    The column acts as the key or part of the key that identifies a set of
    records.
    The column defines the pivot. The values in this column are associated with
    columns in the pivoted dataset.
    The column contains values that are placed in the columns that the pivot
    creates.
    Paul

  • How to create a .mdf SQL Server database from a Data-Tier Application file that has data?

    This is a noob question, though I do use SQL Server databases all the time with Entity Framework when I code in C# using Visual Studio 2013.  The development environment is found below at [A].  I am trying to make a clone of a SQL Server 2008 R2
    database (.mdf)  that exists online.  I can read, connect and work with this database in Visual Studio 2013, but I wish to make a local copy of the database, as an .MDF file.  Somewhere in my notes I have a way of creating a local copy from
    an online database when using Visual Studio but I forgot how (it seems, reviewing my notes, that it deals with ADO.NET which is deprecated in Visual Studio 2013 these days, or so it seems).  So I'm looking for another way.  What I did was create
    (or export) a "Data-Tier Application File" from the online SQL Server database, with data, and it seems to have worked in that this Data-Tier Application file exists on my hard drive and seems to have data in it ("SQL Server Replication Snapshot"
    is the format it seems).  It contains skeleton code to create a database, but when I tried to execute it with SQL Server 2014 Management Studio, I got a bunch of errors.
    So my question is:
    1) Can I somehow create a .MDF SQL Server Database from an Data-Tier Application file that has data?  What tool do I use?  I saw this link, http://social.technet.microsoft.com/wiki/contents/articles/2639.how-to-use-data-tier-application-import-and-export-with-a-windows-azure-sql-database.aspx 
    and it relates to Azure, but is there a tool for C#Visual Studio 2013, standalone?
    2) If there's an easy way to create a .mdf SQL Server Database file from an online file, within SQL Server Management Studio?  I don't think so, since it would require Administrator permissions on the online server, which I don't have. I have permission
    to read, update, delete the online database file, but strangely not to download it (the service I use has a tool for backup, but not for download).
    3) same question as 2), but for Visual Studio 2013?  I don't think so, since I notice none of the templates even mentions ADO.NET anymore, but instead they go with Entity Framework.  Using EF I can of course do anything I want with the online database
    (CRUD), but it remains online.  Maybe there's a switch to make a local copy?  I guess I could write a short program to suck all the data out of the online database and put it into a new, duplicate database having the same tables, that I create on
    my localhost, but my question here is if there's an easier way than this, maybe a tool or command I can run from inside Visual Studio?
    Any advice on any of the above questions is appreciated.
    Thank you,
    Paul
    [A] Microsoft Visual Studio Professional 2013
    Version 12.0.21005.1 REL
    Microsoft .NET Framework
    Version 4.5.51641
    Microsoft Web Developer Tools 2013   2.0.40926.0
    SQL Server Data Tools   12.0.30919.1
    Microsoft SQL Server Data Tools
    Windows Azure Mobile Services Tools   1.0
    Windows Azure Mobile Services Tools

    Thanks but these links are too general to help.
    "2. what do you mean by online file?" - I mean the SQL Server database file is on a remote web server that I rent from, but I am not the administrator of.  I can access my database using SQL Server Authentication, but nothing more.
    Paul
    What do you mean by too general? It explains on how you can use data tier application to create and deploy databases
    May be this will help you to understand better
    http://www.databasejournal.com/features/mssql/article.php/3911041/Creating-Data-Tier-Applications--in-SQL-Server-2008-R2.htm
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • Desc doesn't show datetime columns from SQl Server

    Hi Everyone,
    I have working db link to sql server using hsodbc:
    Oracle 10.2 on AIX using freetds odbc driver version 0.82.
    I can access tables on sql server but oracle sees only varchars and numerics columns in a table.
    Is there a way to select datetime columns from sql server using hsodbc?

    when hsodbc does not show a certain data type it is commonly related to the fact that HSODBC doesn't support the related ODBC data type.
    In general you have a data type in your SQL Server which is mapped to an ODBC data type by the ODBC driver. HSODBC then maps the ODBC data type to an Oracle equivalent and when the ODBC data type isn't supported by HSODBC it just drops it from the select list.
    So for a root cause analysis an ODBC trace is required to determine the mapping of the FreeTDS ODBC driver.
    With this info we can then compare the mapping documented in the HSODBC manual and if the ODBC data type isn't listed as a supported data type you then need to cast the data type on the source side to a different data type (for example varchar/char).
    So please post the ODBC trace and I'll have a look.
    - Klaus
    Edited by: kgronau on Apr 2, 2013 12:50 PM
    BTW, here the link to the HSODBC docu:
    http://docs.oracle.com/cd/B19306_01/server.102/b14232.pdf
    Oracle® Database
    Heterogeneous Connectivity Administrator's Guide
    10g Release 2 (10.2)
    B14232-01
    B.1 Mapping ANSI Data Types to Oracle Data Types Through an ODBC
    Interface

  • Using LV 8.6 to access database created in MS SQL Server Management Studio

    I am using Labview 8.6 to access a database created in MS SQL Server Mgmt Studio, using LabSQL ADO utilities. I don't have LV's add-on DB connectivity toolkit, but just the ADO utilities. Can i do it? If yes, how? I have no experience whatsoever in connecting and accessing data from a DB. An example would help.
    Thanks,

    Szi wrote:
    As for my opinion you cant access without DB connectivity toolkit.
    Nonsense.
    With LabSQL, you should first find an on-line SQL tutorial and refer to the Microsoft help files. I would recomend creating a UDL file. This is the connection string you use for the ADO Connection Open function. You might want to to get a little help from the db administrator. You'll certainly need help in getting a login and password.
    There are examples that come with LabSQL

  • Accessing IMAGE Columns in SQL Server

    I'm trying to use the TG4MSSQL to access tables in a SS2k database. All is well, except for 1 table that has an IMAGE column in it. I must say that I'm a little surprised and disappointed that the 10gR2 gateway for MSSQL apparently translates these things into LONG RAW columns, which are known to be antiquated and minimally supported. However, I still need access to the data, and ultimately, I need it in a BLOB. Doing simple queries (in TOAD) such as:
    select * from image@tg4ss where image_id = 1;
    returns the row, and I can use TOAD to determine that all the data is there. However, apparently, you cannot use PL/SQL to bind more than 32K of this data into a variable, so I haven't had much success there.
    The only way I know of converting a long raw to a blob is to use the to_lob function, but that's only good in the select list of a subquery of an insert statement. Thing is, that doesn't seem to work with the gateway. I tried something like:
    insert into my_blob_table( id, image )
    select id, to_lob(image) as image from image@tg4ss where id = 1;
    That gets me a ORA-00997: illegal use of LONG datatype.
    In fact, I can't even do this:
    insert into my_long_raw_table( id, image )
    select id, image from image@tg4ss where id = 1;
    I get the same error on that command.
    Now, I can do this, but I only get the first 32k of the image:
    begin
    for I in (select id, image from IMAGE@tg4ss)
    loop
    insert into my_long_raw_table( id, image )
    values (I.id, I.image);
    end loop;
    end;
    So, does anyone know how you can get image data out of an SQL Server database into a blob value? If so, I'd appreciate a reply. Thanks.
    -Rich.

    Hello Rich,
    I found your article after running into the same problem. I imagine you've dealt with this one way or another already but just in case...
    The reason the LONG RAW gets truncated is explained in:
    http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14261/datatypes.htm#i43252
    Basically, LONG RAW variables are limited to 32760 bytes inside PL/SQL. The ORA-00997 error is explained a little in:
    http://www.dbaxchange.com/3_4_longdatatypes.htm
    The only solution I found to work was to create a Java utility that read in each LONG RAW value (one at a time) and then update a record in a table's BLOB column. This was even a bit tricky. I found the gateway would lock up if I tried to do too much at a time. I kept it simple my reading all column IDs into an array and then looping through the array while executing a simple select statement that retrieved the LONG RAW value. I concatenated the id to the end of the select statement because prepared statements seemed to be one of the reasons the gateway locked up. I used a ByteArrayInputStream object to populate the BLOB in an update prepared statement for each LONG RAW value processed in the loop.
    - Aaron

  • How mapping sharepoint list Columns to Sql server data table columns programaticlly

    Hi ,
     I have one Verification List in share Point ,in that list i have 10 columns.And we have sql server in that sql server we have one data table Verification_Table
    in that table we have 25 column, my requirement is all list data  move to  sql data table[ what ever columns mapping to list--->data table that data store in data table reaming column is  Null]
     using grammatically not in BCS

    Hello,
    You can create SQL connection and use Datareader to read from SQL.Firs create a connection string and put this string in web application web.config file of your sharepoint site.
    Now use below code to call your connectionstring in your webpart.
    SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["ConnectionString"]);
    Here is link to read the data from SQL:
    http://www.akadia.com/services/dotnet_data_reader.html
    Here is one MSDN link to read SP list data:
    http://msdn.microsoft.com/en-us/library/dd490727%28v=office.12%29.aspx
    Let me know if you have any doubt
    Hemendra:Yesterday is just a memory,Tomorrow we may never see
    Please remember to mark the replies as answers if they help and unmark them if they provide no help

  • Permission denied when creating database in Sql Server 2008 for SQLExpress

    I'm getting an permission error while restoring the database. I'm using SQL Server 2008 SQLEXPRESS
    I'm able to create the user using this script " CREATE LOGIN [darth\vader] FROM WINDOWS;
    GO;"
    But when I try to give role to the user it's still give me permission error.. SP_ADDSRVROLEMEMBER ‘darth\vader’, ‘sysadmin’
    Can someone guide me how to resolve this issue?

    http://msdn.microsoft.com/en-us/library/ms186858.aspx
    Permissions
    If the database being restored does not exist, the user must have CREATE DATABASE permissions to be able to execute RESTORE. If the database exists, RESTORE permissions default to members of the sysadmin and dbcreator fixed
    server roles and the owner (dbo) of the database (for the FROM DATABASE_SNAPSHOT option, the database always exists).
    RESTORE permissions are given to roles in which membership information is always readily available to the server. Because fixed database role membership can be checked only when the database is accessible and undamaged, which is not always the case when RESTORE
    is executed, members of the db_ownerfixed database role do not have RESTORE permissions.
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • How to Encrypt Column in SQL Server?

    Hi all,
    I am using ColdFusion MX 7 and Microsoft SQL Server 2000
    database. I have a column that contains social security numbers of
    my users and am feeling the need to encrypt that column.
    Trouble is, I have no clue how to do this in SQL Server or
    how I could display the data from that column in my web app once
    the column is encrypted.
    Can anyone offer any suggestions?
    Thanks in advance!

    Here's one way...
    To encrypt:
    URLEncodedFormat(Encrypt(yourSStoencrypt,
    application.encKey)) then
    store this value in MSSQL
    To decrypt:
    Decrypt(URLDecode(yourSStodecryptfromDB), application.encKey)
    HTH
    Tim Carley
    www.recfusion.com
    [email protected]

  • Create datasource from SQL Server 2000

    successfully create DB connect source system from Northwind database in SQL Server 2000.
    create datasource and activate, got error:
    @5C\QError@     Event with errors RSDL_META_UPLOAD in DataSource
    @5D\QWarning@     Field name CategoryID contains non-alpha-numeric characters
    How to avoid this error?

    Hi,
    CategoryID have problem. Check data in source system and check data type for CategoryID in BW sys.
    It could be care as CategoryID having some alphabets and while creating info objects in sys you make data type as Number.

  • Folders are creating automatically in Sql Server Report Manger

    Dear All,
    I am using Sql Server Reporting Services. And i have created Diffrent Folders in Report Manager,
    And deployed various reports. Now the problem is one folder created automatically in Report Manager as 'User Folders'
    and in that folder, sub folders are created automatically whenenver users are extracting the reports.
    Iam getting the below error whenever iam going to delete that folders,
    The permissions granted to user 'sbkhetan' are insufficient for performing this operation. (rsAccessDenied)
    Pl help me on this issue. How can i delete that folders,
    Thanks

    That folder is part of the My Reports functionality.  As long as you've got that activated you cannot delete the folder...
    "While the feature is activated, Users Folders and its subfolders cannot be deleted. Furthermore, the name "My Reports" becomes
    a reserved name for folders created under the root node (Home)."
    Ref. Enabling and Disabling My Reports
    MCITP SQL Server 2008 (BI & DEV); MCTS SQL Server 2008 (BI, DEV & DBA)
    Check out my articles at BI: Beer Intelligence?

  • How to export an image column from SQL server to an excel

    Hi team,
    Would like to know how can i get an Image column storeed in SQL Server database to get copied in Excel (Hard Drive).
    Requirement : Need to get Username, User email address and User photo in to an excel sheet from SQL server database.
    Fix: I can get Username and Useremail adress however could not find a way to export /Copy user Image.
    Please suggest
    Thanks,
    venkatesh

    This is an Oracle forum. Your question relates to SQL Server and Excel, neither of which are Oracle related.

  • Problem when create connection to SQl Server ( charecter set cp1255 not found ))

    Hello my name is Ron ,
    i want to connect to SQL SERVER with the microsoft driver
    from Java ( with jDeveloper ) .
    then i did the following steps:
    1) i download and install the jdbc driver for Sql server
    on my machine ( windows XP with , JDK 1.3 )
    2) i update my classpath with the .Jar lib file of the driver .
    3) when creating the connection
    i'm using the
    Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
    this is Ok , the driver was loaded .
    4) when trying the GetConnction
    Connection conn = DriverManager.getConnection
    ("jdbc:microsoft:sqlserver://server1:1433","username","secret");
    i get the following error:
    [Microsoft][SQLServer 2000 Driver for JDBC]Character set CP1255 not found in com.microsoft.util.transliteration.properties.
    please help me with this . any idea ?
    thanks in advance
    Roni

    Ron,
    Try following this document
    http://otn.oracle.com/products/jdev/howtos/bc4j/bc_psqlserverwalkthrough.html
    from the how-tos archive.
    Also, try to change the compiler encoding to UTF-8. you do this in the project setting window.
    http://otn.oracle.com/products/jdev/htdocs/vcmigration/weblogic/unicode.gif
    http://otn.oracle.com/products/jdev/htdocs/vcmigration/weblogic/unicode2.gif
    good luck

  • How can I export image column from SQL Server 2000

    Hi everybody,could someone tell me how can I export an entire column( pictures type) to a folder on disk?I've tried the textcopy.exe under the SQL installation's binn folder,it can only export one picture a time,I'm trying to find an automated way to export
    the whole colum's images to a folder,I'm using SQL Server 2000.

    Vishal,thanks for the replay,I've tried the BCP method but it seems does not work on my Sql Server 2000,also the SSIS package method is demonstrated with Sql Server 2008 R2 and my machine does not have the visual application to try it.In the BCP method,I
    got prompt  indicating me that I wrote something wrong in the grammer,and I'm pretty sure that maybe I made something wrong in the below part,the grammer makes me confused
    INSERT
    INTO @sqlStatements
    SELECT 'BCP "SELECT Photograph_Data FROM [ALBSCH_Trial].[dbo].[Photograph] WHERE Photograph_ID = '''
    + CAST(Photograph_ID AS VARCHAR(500)) + '''" queryout ' + @OutputFilePath
    + CAST(Photograph_ID AS VARCHAR(500)) + '.jpg -S localhost\SQLEXPRESS2008 -T -f C:\SQLTest\Images.fmt'
    FROM dbo.Photograph

Maybe you are looking for

  • MacBook Air Freezes at 50% when booting

    Hi, Sorry if this is posted in the wrong spot. I'm new to the Apple Support forums (well, new to online forums in general). I have a newer MacBook Air that has very recently started to freeze periodically (spinning wheel), and now freezes while booti

  • Find line no in sap script page

    In sap script there are five pages to be printed I want to check in each page the first line exists or not. as well as to identify the first line of each page. How to get a line number for each page in Sap script Please revert back asap Thanks

  • Is there plagiarism checker software for mac

    Does anyone know if there is any plagiarism checker software that apple makes? This would make my life a lot easier with school. Thanks

  • How to find the Schema size

    Hi, How to find the size of the schema in a daabase. Thanks, Mahi

  • Virtual console (Something usefull when Leopard hangs...)

    I'm still looking for the possibility to enable virtual consoles on OSX, in order to rescue Leopard, when it becomes unresponsive, instead of hard shutdown the whole system (it happends quite often). Any tip? I googled and tried with /etc/ttys, but w