Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 insert with sql functions

Author  Topic 

nietzky
Yak Posting Veteran

75 Posts

Posted - 2015-05-08 : 03:23:34
I want to do a simple insert operation on small number of records (less than 200). The problem is I don't know what are the values for TYPE and HRNUM( these values are identity columns and are integers in tblTypes and in table tblHR ).
I do know TYPE string ex. 'LOWER DD' but I need to resolve it to an int, HRNUM can be resolved by passed SID column and returning scalar value. TYPE can be resolvd by passing 'LOWER DD' value to a function

SID TYPE HRNUM IsAvail
u3131 ? ? 0
u3130 ? ? 0
u7133 ? ? 0
u8437 ? ? 0
u3174 ? ? 0
u8136 ? ? 0
u2137 ? ? 0

want to do something like this.

insert into TargetTable
(
TYPE,
HRNUM,
0)
select
a.TYPE,
a.HRNUM,
0
from
@MyTable a

How can I plug in scalar sql functions to this? Target table has identity column.

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2015-05-08 : 09:12:19
the short answer is Yes, you can use a scalar function to return the identity columns. For things like this, I usually just try it out and see what happens, then post my problem if it doesn't work right.

Gerald Britton, MCSA
Toronto PASS Chapter
Go to Top of Page
   

- Advertisement -