How to Get Default Value of a Data Type in SQL Query.

Hi all,
I am creating a procedure which will take input the table name and Column Name.
In the Output i would like to have the data type and default value of that data type which will be used by a another procedure to blank the selected column in the database.
I tried with SET NULL on the column but as the database is of navision the table have property set to NOT NULL.
Here is what i have done till now.
Create Procedure Get_Column_type
@parm_table_name nvarchar(200),
@parm_column_name nvarchar(20),
@parm_result nvarchar(20)OUTPUT
AS
BEGIN 
select @parm_result =
DATA_TYPE from INFORMATION_SCHEMA.COLUMNS IC
where TABLE_NAME = '[' + @parm_table_name +']' and COLUMN_NAME = '[' + @parm_column_name + ']'
END
GO
Now instead on write a case statement for so many data types in SQL, i was thinking is it possible someway that above procedure also returns the default value which i can set in another procedure.
Let me know if its possible or not? Thanks in advance.

Do you looking for something like this?
create table t10 ( c int default 1)
SELECT so.name AS table_name, 
          sc.name AS column_name, 
          sm.text AS default_value
     FROM sys.sysobjects so
     JOIN sys.syscolumns sc ON sc.id = so.id
LEFT JOIN sys.syscomments SM ON sm.id = sc.cdefault
    WHERE so.xtype = 'U' 
      AND SO.name = 't10'
 ORDER BY so.[name], sc.colid
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

Similar Messages

  • How to get the values from struct data type using java code..?

    Hi ,
    I am newer to java.
    we are using oracle database.
    How to get the data from struct data type using java code.
    Thanks in Advance.
    Regards,
    kumar

    Hi Rajeev,
    To retrieve a FilterContainer you will need to traverse the report structure:
    ReportStructure boReportStructure = boDocumentInstance.getStructure();
    ReportContainer boReportContainer = (ReportContainer) boReportStructure.getReportElement(0);
    FilterContainer boFilterContainer = null;
    if (boReportContainer.hasFilter()) {
         boFilterContainer = boReportContainer.getFilter();
    } else {
         boFilterContainer = boReportContainer.createFilter(LogicalOperator.AND);
    Calling boDocumentInstance.getStructure() will retrieve the entire structure for the document.
    Calling boReportStructure.getReportElement(0) will retrieve the structure for the first report of the document.
    Hope this helps.
    Regards,
    Dan

  • How to get maximal value from the data/class for show in Map legend

    I make WAD report that using Map Web Item.
    I devide to four (4) classes for legend (Generate_Breaks).
    I want to change default value for the class by javascript and for this,
    I need to get maximal value from the class.
    How to get maximal value from the data/class.
    please give me solution for my problem.
    Many Thx
    Eddy Utomo

    use this to get the following End_date
    <?following-sibling::../END_DATE?>
    Try this
    <?for-each:/ROOT/ROW?>
    ==================
    Current StartDate <?START_DATE?>
    Current End Date <?END_DATE?>
    Next Start Date <?following-sibling::ROW/END_DATE?>
    Previous End Date <?preceding-sibling::ROW[1]/END_DATE?>
    ================
    <?end for-each?>
    o/p
    ==================
    Current StartDate 01-01-1980
    Current End Date 01-01-1988
    Next Start Date 01-01-1990
    Previous End Date
    ================
    ==================
    Current StartDate 01-01-1988
    Current End Date 01-01-1990
    Next Start Date 01-01-2005
    Previous End Date 01-01-1988
    ================
    ==================
    Current StartDate 01-01-2000
    Current End Date 01-01-2005
    Next Start Date
    Previous End Date 01

  • How to get default values while using the transaction "BP"

    Hi Group,
    I have a query on how to get default values while using the transaction <b>BP</b>?
    The thing is:
    when I enter into the transaction "BP", I need to see some default values to some of the input fields in the screen.
    how can I achieve this?
    So please kindly let me know the procedure to achieve this.
    Thanks & Regards,
    Vishnu.

    Hi,
    The events of BDT can be used to default some fields on creating a partner.
    For this create a function module for ISDAT. attach that event in BUS7.
    In the ISDAT funtion modulethe following code should be used.
    For example to set the nationality:
    I_BUSDEFAULT-NATIO = 'DE.
    CALL FUNCTION 'BUP_BUPA_FIELDVALUES_SET'
    EXPORTING
    i_busdefault = I_BUSDEFAULT
    Regards, Smita.

  • How to show the VALUE as the Column Header using SQL query?

    Hi
    I have a requirement to show the picked value as the column header using SQL query.
    Example:
    ======
    SELECT EMPNO FROM EMP
    WHERE EMPNO=7934;
    Result Should be:
    7934
    7934

    I have a requirement to show the picked value as the column header using SQL query.In sql*plus you can do
    SQL> set verify on
    SQL> def e =  7934
    old: SELECT empno "&&e"  FROM emp  WHERE empno = &&e
    new: SELECT empno "7934"  FROM emp  WHERE empno = 7934
    SQL> SELECT empno "7934"  FROM emp  WHERE empno = 7934
          7934
          7934
    1 row selected.

  • How to get previous values based on date filters

    Hi
    i have two fields gldate and startdate
    gldate values are like 1/31/2011,2/28/2011,3/31/2011,4/30/2011,5/31/2011 ...
    startdate values 1/1/2011,2/1/2011,3/1/2011,4/1/2011,5/1/2011 ...
    i need a condition like gldate<startdate
    if startdate is 11/1/2011 then i get all the values before 11/1/2011 values
    im using filter for date filed
    let us filter values is startdate--11/1/2011 and gldate is 11/30/2011 but that cond falls
    how to get this condition
    plz its urgent to me

    Hi
    i have two fields gldate and startdate
    gldate values are like 1/31/2011,2/28/2011,3/31/2011,4/30/2011,5/31/2011 ...
    startdate values 1/1/2011,2/1/2011,3/1/2011,4/1/2011,5/1/2011 ...
    i need a condition like gldate<startdate
    if startdate is 11/1/2011 then i get all the values before 11/1/2011 values
    im using filter for date filed
    let us filter values is startdate--11/1/2011 and gldate is 11/30/2011 but that cond falls
    how to get this condition
    plz its urgent to me

  • How to get default values on selection screen(multiple ranges)?

    i want to know how to maintain default ranges in selection screen...like 2000 to 3000 and 7000 to 8000 and 11000 to 15000
    all the above ranges must get by default how to provide those to selection screen by default...please give me idea...with example...

    Hi Suresh,
    You can either use select-options or Ranges. If you want the selection screen to be displayed with allwoing user to enter values apart for the default ones use select options else use ranges. With ranges what ever values use hard code would be set and the end user will not be able to add any more values (or range of values).
    Simply write the following code
    tables : <name of the table from which the field belongs>
    select-options <fieldname> for <tablename>-<fieldname>.
    <fieldname>-sign = 'I'.
    <fieldname>-option = 'BT'.
    <fieldname>-low = '7000'.
    <fieldname>-high = '8000'.
    append <fieldname>..
    similiarly add all the ranges that you need to include as default and in your select statement use the IN operator inthe where clause to include the range.
    If using range replacethe select-option with the range statement.
    Thanks.

  • How to set default value to current date in Webcenter Imaging Application?

    Hi
    I have created an application in Webcenter Imaging and have a field called as ScanDate.
    While uploading documents against that particular application, i want that ScanDate field should default to Current Date.
    I tried setting the default value but it becomes a static date.
    Can anyone suggest me what to do in this case?
    Regards
    ACM

    You can't do that anyway. The default values are saved as part of the VI and a built application can not do that. Instead, you will have to do this yourself by saving the data to a file, loading it and wiring it into a local variable of the control. You can do this, for example, with the configuration file VIs or, if you want to rely on the good work that other people already did, you can go to the OpenG site and download their file package, which includes saving control values to INI files.
    Try to take over the world!

  • How do I pull SharePoint 2013 list data using a SQL Query

    I have been asked to write a sql query to pull data from a SharePoint 2013  List.it needs to return all the columns
    Basically a Select all from the specific SharePoint list Database
    I do have the  list GUID ID. But not sure  which  SQL Table or Database to look in for list data.. the site and the list is in our main SharePoint site collection.
    the query only needs to be saved in SQL server

    I know it isn't support but sometimes you have to share data with other programs....
     I'm stuck.. I was able to get this far...
    SELECT * FROM dbo.Lists
    where tp_Title ='List Name'
     how do I pull the columns of the list?
    I think I still need the specific list not just the master list dbo....
    those two links do not work for SQL server  and SharePoint 2013

  • How to pass parameter value as "where [fieldname] = [fieldvalue]" in sql query under query type in SSRS report?

    I am having trouble with passing dynamic string to sql query for executing SSRS reports.
    I am using oracle database and I want to pass where clause parameter as "where LAND_NR = 6" to my select query.
    For example: I want to execute Select * from employee :p_where.
    where p_where parameter holds value "where LAND_NR = 6"
    So it will treat as "Select * from employee where LAND_NR = 6" statement which will give me the list of records to display in my reports.
    But it's not taking correct sql command throwing an error as "SQLcommand not properly ended."
    How can I achieve this?

    You need to use dynamic sql
    But please keep in mind that since you're using Oracle you may be better off posting this in some Oracle forums
    This forum is specifically for SQL Server
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • Problems with java constructor: "inconsistent data types" in SQL query

    Hi,
    I tried to define a type "point3d" with some member functions, implemented in java, in my database. Therefor I implemented a class Point3dj.java as you can see it below and loaded it with "loadjava -user ... -resolve -verbose Point3dj.java" into the database.
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    package spatial.objects;
    import java.sql.*;
    public class Point3dj implements java.sql.SQLData {
    public double x;
    public double y;
    public double z;
    public void readSQL(SQLInput in, String type)
    throws SQLException {
    x = in.readDouble();
    y = in.readDouble();
    z = in.readDouble();
    public void writeSQL(SQLOutput out)
    throws SQLException {
    out.writeDouble(x);
    out.writeDouble(y);
    out.writeDouble(z);
    public String getSQLTypeName() throws SQLException {
    return "Point3dj";
    public Point3dj(double x, double y, double z)
    this.x = x;
    this.y = y;
    this.z = z;
    public static Point3dj create(double x, double y, double z)
    return new Point3dj(x,y,z);
    public double getNumber()
         return Math.sqrt(this.x*this.x + this.y*this.y + this.z*this.z);
    public static double getStaticNumber(double px, double py, double pz)
         return Math.sqrt(px*px+py*py+pz*pz);
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Additionally, I created the corresponding type in SQL by
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    CREATE OR REPLACE TYPE point3dj AS OBJECT EXTERNAL NAME
    'spatial.objects.Point3dj' LANGUAGE JAVA USING SQLDATA (
    x FLOAT EXTERNAL NAME 'x',
    y FLOAT EXTERNAL NAME 'y',
    z FLOAT EXTERNAL NAME 'z',
    MEMBER FUNCTION getNumber RETURN FLOAT
    EXTERNAL NAME 'getNumber() return double',
    STATIC FUNCTION getStaticNumber(xp FLOAT, yp FLOAT, zp FLOAT) RETURN FLOAT
    EXTERNAL NAME 'getStaticNumber(double, double, double) return double')
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    After that I tried some SQL commands:
    create table pointsj of point3dj;
    insert into pointsj values (point3dj(2,1,1));
    SELECT x, a.getnumber() FROM pointsj a;Now, the problem:
    Everything works fine, if I delete the constructor
    public Point3dj(double x, double y, double z)
    this.x = x;
    this.y = y;
    this.z = z;
    in the java class, or if I replace it with a constructor that has no input arguments.
    But with this few code lines in the java file, I get an error when executing the SQL command
    SELECT x, a.getnumber() FROM pointsj a;The Error is:
    "ORA-00932: inconsistent data types: an IN argument at position 1 that is an instance of an Oracle type convertible to an instance of a user defined Java class expected, an Oracle type that could not be converted to a java class received"
    I think, there are some problems with the input argument of the constructor, but why? I don't need the constructor in SQL, but it is used by a routine of another java class, so I can't just delete it.
    Can anybody help me? I would be very glad about that since I already tried a lot and also search in forums and so on, but wasn't successful up to new.
    Thanks!

    Dear Avi,
    This makes sense when it is a short code sample (and i think i've done that across various posts), but sometime this is too long to copy/paste, in these cases, i refer to the freely available code samples, as i did above on this forum; here is the quote.
    Look at examples of VARRAY and Nested TABLES of scalar types in the code samples of my book (chapter 8) http://books.elsevier.com/us//digitalpress/us/subindex.asp?maintarget=companions/defaultindividual.asp&isbn=9781555583293&country=United+States&srccode=&ref=&subcode=&head=&pdf=&basiccode=&txtSearch=&SearchField=&operator=&order=&community=digitalpress
    As you can see, i was not even asking people to buy the book, just telling them where to grab the code samples.
    I appreciate your input on this and as always, your contribution to the forum, Kuassi

  • How to get default value using VA

    using jdev 11.1.1.6.2
    I defined a transient attribute with a default expresssion as
    oracle.jbo.Row r = getPayeeNameVA().first();
    if(r != null)
    return r.getAttribute("PartyName");
    I have a VO named PayeeVO with a vc haiving one bind variable. This VO is used to create PayeeNameVA view accessor. In PayeeNameVA the default VC is shuttled and value is bound to one of the view attribute.
    However, on running the app I get below exception. please advise
    aused by: oracle.jbo.JboException: JBO-29000: Unexpected exception caught: org.codehaus.groovy.runtime.typehandling.GroovyCastException, msg=Cannot cast object 'oracle.jbo.script.ExprEvalWrapper@3b50bd53' with class 'oracle.jbo.script.ExprEvalWrapper' to class 'oracle.jbo.Row'
         at oracle.jbo.ExprEval.internalEvaluateGroovyScript(ExprEval.java:1411)
         at oracle.jbo.ExprEval.doEvaluate(ExprEval.java:1457)
         at oracle.jbo.ExprEval.doEvaluate(ExprEval.java:1435)
         at oracle.jbo.ExprEval.evaluateForRow(ExprEval.java:1217)
         at oracle.jbo.server.AttributeDefImpl.evaluateTransientExpression(AttributeDefImpl.java:2262)
         at oracle.jbo.server.ViewRowStorage.getAttributeInternal(ViewRowStorage.java:1884)
         at oracle.jbo.server.ViewRowImpl.getAttributeValue(ViewRowImpl.java:1940)
         at oracle.jbo.server.ViewRowImpl.getAttributeInternal(ViewRowImpl.java:883)
         at oracle.apps.afg.creditRules.model.view.CreditReceiversVORowImpl.getPayeeName(CreditReceiversVORowImpl.java:780)
         at oracle.apps.afg.creditRules.model.view.CreditReceiversVORowImpl$AttributesEnum$2.get(CreditReceiversVORowImpl.java:39)
         at oracle.apps.afg.creditRules.model.view.CreditReceiversVORowImpl.getAttrInvokeAccessor(CreditReceiversVORowImpl.java:830)
         at oracle.jbo.server.ViewRowImpl.getAttribute(ViewRowImpl.java:913)
         at oracle.jbo.uicli.binding.JUCtrlValueBinding.internalGetAttributeValueFromRow(JUCtrlValueBinding.java:1137)
         at oracle.jbo.uicli.binding.JUCtrlValueBinding.getAttributeFromRow(JUCtrlValueBinding.java:731)

    Hi,
    apparently you access the wrong object, which is ExprEvalWrapper, and this cannot be cast to the Row object you really want to work with. I assume that Row is wrapped by this class. However, the ExprEvalWrapper is for internal framework use and the super class, which is org.codehaus.groovy.runtime.wrappers.PojoWrapper, exposes the getWrappeed method as a protected method. Without knowing your exact use case I think you will need to find another solution (e.g. expose a method on the entity impl class you then call from Groovy)
    Frank

  • How to split a value of currency data type...........?

    Hi Abapers,
                       Is there any way by which we can spit values like 1000.11
    i just want the values after decimal like 11 in this case
    Is it possible...?

    The answer is true with a NUMC/decimal field, but is false with a CURR/currency field, not every currency has 2 decimals (most have but not all) so when conversion to character you MUST use a
    WRITE <currfield> CURRENCY <cucyfield> TO <charfield>
    Look at [CURRENCY cur |http://help.sap.com/abapdocu/en/ABAPWRITE_TO_OPTIONS.htm#!ABAP_ADDITION_6@6@] in [WRITE - format_options|http://help.sap.com/abapdocu/en/ABAPWRITE_TO_OPTIONS.htm]
    Regards,
    Raymond

  • Selecting values between 2 dates for an SQL query report region

    I have a region where im selecting between 2 dates
    select hp.NAME, hp.VALUE, hp.UPDATEDATE, hp.DESCRIPTION, hp.UPDATE_COMMENT, hp.HASH, hp.IDCATEGORY
    from HIST_REPORT hr, HIST_PARAM hp
    where hp.dbid = hr.dbid and hr.id = :P7_ID and hp.UPDATEDATE between :P7_BDATE and :P7_EDATE
    The problem is that if I have a row thats dated today (april 1) and if I set the beginning date (BDATE) to april 1 as well as the ending date (EDATE), no rows show and I would like the april 1 row to show. How can I modify my query to fix this?

    and hp.UPDATEDATE between :P7_BDATE
        and decode(:P7_EDATE,:P7_BDATE,:P7_EDATE+1,:P7_EDATE)This assumes, though, that the time component of your items is implicitly 00:00.
    Joel

  • How to get save result from EXECUTE from a dynamic SQL query in another table?

    Hi everyone, 
    I have this query:
    declare @query varchar(max) = ''
    declare @par varchar(10)
    SELECT @par = col1 FROM Set
    declare @region varchar(50)
    SELECT @region = Region FROM Customer
    declare @key int
    SELECT @key = CustomerKey FROM Customer
    SET @query = 'SELECT CustomerKey FROM Customer where ' + @par + ' = '+ @key+ ' '
    EXECUTE (@query)
    With this query I want get col1 from SET and compare it to the column Region from Customer. I would like to get the matching CustomerKey for it.
    After execution it says commands are executed successfully. But I want to save the result from @query in another table. I looked it up and most people say to use sp_executesql. I tried a few constructions as sampled and I would always get this error: 
    Msg 214, Level 16, State 2, Procedure sp_executesql, Line 12
    Procedure expects parameter '@statement' of type 'ntext/nchar/nvarchar'.
    So the output should be a list of CustomerKeys in another table.
    How can I save the results from EXECUTE into a variable? Then I assume I can INSERT INTO - SELECT in another table. 
    Thanks

    CREATE TABLE Customer
    (CustomerKey INT , Name NVARCHAR(100));
    GO
    INSERT dbo.Customer
    VALUES ( 1, N'Sam' )
    GO
    DECLARE @query nvarchar(max) = ''
    declare @par varchar(10) = 'Name',
    @key varchar(10) = 'Sam'
    CREATE TABLE #temp ( CustomerKey INT );
    SET @query =
    insert #temp
    SELECT CustomerKey
    FROM Customer
    where ' + @par + ' = '''+ @key+ ''' '
    PRINT @query
    EXEC sp_executesql @query
    SELECT *
    FROM #temp
    DROP TABLE #temp;
    DROP TABLE dbo.Customer
    Cheers,
    Saeid Hasani
    Database Consultant
    Please feel free to contact me at [email protected] as well as on Twitter and Facebook.
    [My Writings on TechNet Wiki] [T-SQL Blog] [Curah!]
    [Twitter] [Facebook] [Email]

Maybe you are looking for