存储过程:执行输出参数时不显示列名称

时间:2017-08-22 19:19:59

标签: sql-server

我创建了一个存储过程,它是输出参数。

create proc sp_withoutputparameter
@Gender nvarchar(50),
@employeecount int output
as
begin
select @employeecount=count(id) from temployee where gender=@Gender
end


declare @Totalcount int 
execute sp_withoutputparameter @employeecount=@Totalcount  out,@Gender='Female' 
print @Totalcount

execute sp_withoutputparameter @employeecount=@Totalcount  out,@Gender='Female' 
select @Totalcount 

Screen shot 1 执行上述查询后。我收到附件Screen shot 2中显示的结果 在两个查询中我都使用print并在两个结果中选择我没有得到列名。

请帮助我解决这个问题,我应该怎么做才能在查询中做一些修改以显示列名???

2 个答案:

答案 0 :(得分:1)

由于您只是输出变量,因此它没有列名。如果你想添加一个,只需使用别名。

select @TotalCount as 'Total # of Female Employees'

答案 1 :(得分:0)

看起来像SQL Server,而不是MySQL,对吗?由于您正在选择/打印变量,因此它没有要放入标题的“列”名称。你试过了吗?

async.eachSeries(nc.virtual_devices, function iteratee(vd, cb) {
    console.log('calling iteratee()')

    var domain = extractDomain(vd.api_url);
    vd.raw_api_ip = vd.api_ip;
    vd.api_ip = getProxiedPath(vd.api_ip);
    vd.raw_api_url = vd.api_url;
    vd.api_url = nconf.get('PROXIED_PATH_SCHEME') + vd.api_ip + vd.api_url.split(domain)[1];
     // Path to websocket notifications
    vd.ws_url = nconf.get('PROXIED_PATH_SCHEME') + vd.api_ip + vd.notification_base_uri;

    // skip the rest if type is XXX;
    // you need to explicitedly call the original callback i.e. cb
    // note the use of return to prevent execution of the rest of the code
    if (nc.type !== 'XXX')
        return cb(null); // or cb();

    console.log("********XX VD TYPE **********");
    console.log(JSON.stringify(vd));
    console.log("VD ID VALUE IS ", vd.id);
    var newID = (vd.id).replace(/\d_/, "");
    console.log("VD ID VALUE IS ", newID);

    // I have no idea what is going here
    var _idofSubgroup;
    var labeltoSearch = nc.type + ' ' + nc.version;
    var pattern = "/^" + newID + "/i";
    test = _idofSubgroup;
    pattern = newID;
    console.log(pattern);

    // we're going to use waterfall here as you have 2 async operations, where one is dependent on the other 
    async.waterfall([
        function getSubgroup(cb1) {
            console.log('calling getSubgroup')
            db.collection('subgroups').findOne({ label: labeltoSearch }, function (err, subgroup) {
                // if an error occurs, stop waterfall-loop
                // you do this by passing the error in the callback
                // again note the use of return here to prevent execution of the rest of the code
                if (err) return cb1(err);
                // pass the data to the next task
                cb1(null, subgroup, pattern);
            });
        },
        function getPosts(subgroup, pattern, cb2) {
            // we will only get here if the last task ^ went through
            console.log('calling getPosts')
            db.collection('exploreposts').find({ subgroup: subgroup._id, title: { $regex: pattern }}).toArray(function (err, posts) {
                // if an error occurs, stop waterfall-loop
                if (err) return cb2(err);
                // do something with posts
                console.log('posts', posts);
                // otherwise, keep going
                // since there are no more waterfall-tasks, waterfall ends
                cb2();
            });
        }
    ], function (err) {
        console.log('waterfall() done');
        // if an error occurred during the waterfall-loop, it will come down here
        // we will let the original callback i.e. cb deal with this error though
        if (err) return cb(err);
        // otherwise we're done
        // we will let the original callback know everything went well by calling it without any error
        cb();
    });

    // you could have also simply do
 // ], cb);


}, function (err) {
    console.log('eachSeries() done');
    // handle any error that came
    console.log(err);
    // send response
});

print命令没有标题,也不应该。它旨在打印用户定义的消息。 https://docs.microsoft.com/en-us/sql/t-sql/language-elements/print-transact-sql

你可以......

select @TotalCount as TotalCount

这就是你如何获得TSQL打印语句的标题。

相关问题