Urgent help with default value Or Binding MSSQL

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tezza98
    New Member
    • Mar 2007
    • 38

    Urgent help with default value Or Binding MSSQL

    Help please, Im using SQL server Management Studio Express and i want to change the default value of a varchar(50) column.
    i want the defaultdate to be like this

    '5/04/2007 11:15 pm System generated'
    So i have tried to do this:

    (getDate())+'Sy stem generated'
    (getdate()).'Sy stem generated'
    but neither seem to work

    these two actually put the entire string as the default value so the default values are
    (getDate())+'Sy stem generated'
    (getdate()).'Sy stem generated'


    is there something that i am missing

    Also, is there a way that i can make the default value = another field in the table so the default value would be another field
  • iburyak
    Recognized Expert Top Contributor
    • Nov 2006
    • 1016

    #2
    Change default to this:

    [PHP]DEFAULT Convert(varchar (20),getdate(), 100) + ' System generated'[/PHP]

    No, another column can not be a default. But you can write a trigger over this table to change value of a column.

    Good Luck.

    Comment

    • tezza98
      New Member
      • Mar 2007
      • 38

      #3
      Originally posted by iburyak
      Change default to this:

      [PHP]DEFAULT Convert(varchar (20),getdate(), 100) + ' System generated'[/PHP]

      No, another column can not be a default. But you can write a trigger over this table to change value of a column.

      Good Luck.

      Thanks, I know how to do it in PHP, i did some research, and your right, you cant dynamically create a unique default value

      Anyway Ive figured out a solution, whoever made the table set up two fields, one called SampleNumber, and one called SampleNumberNul l

      SampleNumberNul l uses this computed Column Spec
      Code:
      (case when [SampleNumber] IS NULL then [ID] else (0) end)
      which in reality holds the default value that for samplenumber.

      ID is the primary key autonumber

      So what i did is and update query
      Code:
       UPDATE Table SET SampleNumber = SampleNumberNull WHERE SampleNumber IS NULL
      which will make all the samplenumber not null, now i just have to find the right spot in the code to execute it...

      Comment

      Working...